我制作了一个复合控件,但是当我将此新组件添加到具有其他标准组件(例如 TextView)的 XML 层中时,当该层膨胀时,复合控件在底部添加了一个很大的边距,将其与其他组件分开。我尝试添加 Layer_bottomMargin = 0dp 没有成功,解决这个问题的唯一方法是添加 layer_height 一个固定值(即 15dp)而不是“wrap_content”,但是这个解决方案对我来说并不好,因为我想从我的化合物中删除一些组件控制。
我的复合控件的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left|top"
android:clickable="false"
android:background="#CCCCCC"
android:layout_marginTop="@dimen/fieldset_margin"
>
<TextView
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/title_default"
android:textSize="14sp"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/fieldset_lines_shadow"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/fieldset_lines_light"
/>
</LinearLayout>
我的层的代码包括这个复合控件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#C8D5F6FF"
android:gravity="top"
android:layout_margin="8dp"
>
<com.apps.example.Header
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/fieldset_text_secondary"
android:text="nananananan"
android:textSize="10sp"
android:layout_marginLeft="@dimen/fieldset_margin"
/>
</LinearLayout>
抱歉,这是我的第一篇文章,我无法上传图片。
提前致谢。