AM用自定义布局构建可扩展线性布局的android模块。我想设置我的自定义布局被放大时希望子布局加载的位置
在我的自定义布局中,我具有以下代码
public class CustomLayout extends LinearLayout {
public CustomLayout(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
context = context;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (isInEditMode())return;
setOrientation(VERTICAL);
LayoutInflater.from(getContext()).inflate(R.layout.custom_layout_template, this, true);
}
}
所以我有我的自定义布局模板
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_margin="5dp"
android:id="@+id/offlineViewer"
android:layout_width="match_parent"
android:background="#4B4848"
android:gravity="center"
android:padding="5dp"
android:layout_height="wrap_content">
<TextView
android:textSize="13sp"
android:textStyle="italic"
android:gravity="center"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your device is offline"
/>
</RelativeLayout>
//LOAD THE CONTENT HERE
</LinearLayout>
</merge>
因此,在我要加载此布局的其他活动布局中,我想将内容加载到相对布局下方。那是我的另一项活动,正在通过
加载上述自定义布局<com.dev.testapp.CustomLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Texview
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:text="my activity content"
/>
</RelativeLayout>
</com.dev.testapp.CustomLayout>
以上运行没有任何错误,但是我想将内容放置在offlineviewer相对布局下方的自定义布局中。
由于每次加载自定义布局内容都会被加载布局完全覆盖,因此我该如何实现这一点