0
我有一個自定義視圖,它使用佈局來膨脹其中的子視圖。自定義ViewGroup在視圖層次結構中創建兩個節點
當此視圖中創建和膨脹,視圖層次結構有兩個加N的觀點:
MyCustomView -> RelativeLayout -> {subview1, subview2,…}
有什麼辦法消除RelativeLayout的節點?
相關類:
class MyCustomView extends RelativeLayout {
...
public void start(Context context) {
final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.view_custom, this);
}
...
}
相關XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#232323">
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/view_video"
android:paddingTop="@dimen/activity_vertical_margin_medium"
android:paddingBottom="@dimen/activity_vertical_margin_slim"
android:paddingRight="@dimen/activity_vertical_margin_medium"
android:gravity="left"
android:text="@string/video_title"
android:textSize="@dimen/text_size_largest"
android:textColor="@color/text_login_gray"
android:textAllCaps="true"
android:background="#232323" />
<TextView
android:id="@+id/tv_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_title"
android:layout_alignLeft="@+id/tv_title"
android:paddingBottom="@dimen/activity_vertical_margin_medium"
android:paddingRight="@dimen/activity_vertical_margin_medium"
android:gravity="left"
android:text="@string/video_desc"
android:textSize="@dimen/text_size_small"
android:textColor="@color/text_very_light_gray"
android:background="#232323" />
</RelativeLayout>
使用'merge'標籤。 – Luksprog
當我用'合併'替換RelativeLayout時,如何修復Android Studio預覽中的時髦外觀? –