我有课
public class CompactFeedItemView extends LinearLayout {
public CompactFeedItemView(Context context,MyObject a) {
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.compactfeedviewitem,this,true);
}
}
然后我有 compactfeedviewitem.xml 文件:
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:id='@+id/feedViewItemOuterLayout'
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/compactfeedborder"
>
<ImageView android:id="@+id/feedItemIcon"
android:src="@drawable/missing"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:adjustViewBounds="true"
/>
</merge>
这行得通, ImageView 被合并并添加为 subview ,但它忽略了 android:layout_marginTop="10dp" android:layout_marginBottom="10dp" 来自合并标签的属性。
那么我该如何合并属性,或者这是不可能的? 我可以改成 .这会起作用,但随后我为我创建的每个 CompactFeedItemView 得到了一个额外的无用 LinearLayout 元素。这正是我想通过合并避免的。
最佳答案
我不认为这是可能的,因为 merge
标签的全部意义在于删除不必要的 ViewGroup
对象并指定属性(如边距)需要ViewGroup
对象放置在 View 层次结构中。
关于android - 合并标签的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18081336/