我已经在该论坛上搜索了文章和搜索问题,都只显示了“如何设置gradle子目录”
我已经设置了build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.ardyfeb.kolabs"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
res.srcDirs = [
'src/main/res/layout/partials',
'src/main/res/layout',
'src/main/res'
]
}
}
}
dependencies {
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:multidex:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:design:+'
compile 'com.android.support:support-v13:+'
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
我的目录树
src/main/res
-- layout
- main.xml
-- partials
- header.xml
我的问题是:
如何包含partials/header.xml
?带有标签
示例:
<include
layout="@layout/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/header"/>
答案 0 :(得分:0)
<include
android:id="@+id/tagOne"
layout="@layout/header"
...
/>
和
<include
android:id="@+id/tagTwo"
layout="@layout/header"
...
/>
示例
如果您有TextView
,则可以按如下标记查找视图
TextView headerOneText = findViewById(R.id.tagOne).findViewById(R.id.textView);
和
TextView headerTwoText = findViewById(R.id.tagTwo).findViewById(R.id.textView);