Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 复合控制中的大余量底部_Android - Fatal编程技术网

Android 复合控制中的大余量底部

Android 复合控制中的大余量底部,android,Android,我制作了一个复合控件,但是当我将这个新组件与其他标准组件(例如TextView)一起添加到XML层时,当这个层膨胀时,复合控件在底部添加了一个很大的边距,将其与其他组件分开。我尝试添加Layer_bottomMargin=0dp,但没有成功,解决此问题的唯一方法是将Layer_高度添加为一个固定值(即15dp),而不是“包裹内容”,但此解决方案对我来说不合适,因为我想从复合控件中删除一些组件 我的复合控件的代码: <LinearLayout xmlns:android="http://sc

我制作了一个复合控件,但是当我将这个新组件与其他标准组件(例如TextView)一起添加到XML层时,当这个层膨胀时,复合控件在底部添加了一个很大的边距,将其与其他组件分开。我尝试添加Layer_bottomMargin=0dp,但没有成功,解决此问题的唯一方法是将Layer_高度添加为一个固定值(即15dp),而不是“包裹内容”,但此解决方案对我来说不合适,因为我想从复合控件中删除一些组件

我的复合控件的代码:

<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> 

我的图层的代码包括这个复合控件:

<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> 

抱歉,这是我的第一篇帖子,我无法上传图片


提前感谢。

我通过覆盖复合控件类中的onMeasure方法部分解决了问题。我以前没有这样做,因为在官方文件中:

表示在创建复合控件时不必覆盖此方法

无论如何,这是部分解决方案,因为当化合物的单个控件以编程方式变为不可见(消失)时,会出现与原始文章中提到的相同的问题,但边距空间较小

我将继续努力解决这个问题,但现在,这是我的解决方案

谢谢