android - 合并标签的属性

标签 android layout

我有课

    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/

相关文章:

android - 如何在Android中默认打开一个 fragment ?如何签署被点击的按钮?

android - 是否有带有标签的 float 操作按钮 (FAB) 库?

android - Azure 移动应用程序 node.js 后端 Android 客户端 - 50 行限制

silverlight - 如何使 ContentControl 水平拉伸(stretch)

javascript - 使用 ng-repeat 时了解 Angular 布局

android - Android 滑动 ListView 布局

android - Android Web 浏览器会像 iPhone 上的 Safari 那样缩小内容吗?

swift - 在头部 View 中设置按钮

用于翻阅基于 JPane 的 View 的 Java Swing 架构

android - 如何在android中动态更改自定义 View