假設我們正在開發基於LinearLayout的複合組件。所以,我們創建類是這樣的:在Intellij IDEA/Android Studio中預覽具有合併根標籤的佈局
public class SomeView extends LinearLayout {
public SomeView(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(LinearLayout.VERTICAL);
View.inflate(context, R.layout.somelayout, this);
}
}
如果我們將使用LinearLayout
作爲somelayout.xml
根,我們將有額外的視圖的水平,所以我們使用合併標籤:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some other text"/>
</merge>
但在在IDE合併預覽標籤總是作爲FrameLayout裏,我們會看到類似的東西:
(這是Android的工作室,IntelliJ IDEA的是一樣的,關於Eclipse我不知道)
預覽加速開發佈局很多,即使對於某些佈局,也會失去這麼大的幫助。可能有一種方法可以指定,Preview應該如何解釋merge
特定佈局中的標籤?
我想看到這種支持添加。 –
這個工具屬性可能在未來某個時候可以解決。 https://code.google.com/p/android/issues/detail?id = 61652 – Jonas