Android 布局\u高度始终包装内容

Android 布局\u高度始终包装内容,android,android-layout,Android,Android Layout,这只是一个简单的问题: 我有一个布局文件,它作为列表视图中的一个项目显示。我将RelativeLayout的高度设置为100dp,但它不起作用,它总是包装内容,无论我使用哪种布局。如何将布局高度设置为固定值而不进行包装 谢谢你的帮助 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

这只是一个简单的问题:

我有一个布局文件,它作为列表视图中的一个项目显示。我将RelativeLayout的高度设置为100dp,但它不起作用,它总是包装内容,无论我使用哪种布局。如何将布局高度设置为固定值而不进行包装

谢谢你的帮助

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="100dp"> <!-- this attribute seems to be ignored -->

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:orientation="horizontal"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_centerHorizontal="true">

        <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_width="@dimen/progressbar_small"
                 android:layout_height="@dimen/progressbar_small"
                 android:layout_gravity="center_vertical" />

        <TextView xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="5dp"
                 android:text="@string/loading"
                 android:layout_gravity="center_vertical"
                 style="@style/ListItemSubtext" />

     </LinearLayout>
 </RelativeLayout>


尝试使用100px。适合我。

我对您的xml做了以下更改

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="100dp"> <!-- this attribute taking a fixed value as u said -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_centerHorizontal="true" 
             android:layout_width="fill_parent" 
             android:layout_height="fill_parent" 
             android:orientation="horizontal">

    <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_gravity="center_vertical" 
             android:layout_width="20dip" 
             android:layout_height="20dip"/>

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginLeft="5dp"
             android:text="@string/loading"
             android:layout_gravity="center_vertical"
             style="@style/ListItemSubtext" />

 </LinearLayout>


如果这对您不起作用,请说出您到底想做什么。

我认为在列表视图中,所有项目的高度都相同。在您的情况下,可以在列表页脚视图中添加进度条。在ListItemSubtext之前或之后添加虚拟高度调节器。尝试使用TableLayout,而不是相对和线性布局

虚拟调节器是这样的

<View android:layout_width="wrap_content" android:layout_height="100dip"/>

请注意,并非每个元素都需要xmlns。

请执行以下操作:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:minHeight="100dip">


尝试对所有嵌套视图应用相同的高度限制。此外,这是一个切线,但在显示的xml中不需要线性布局。永远不要使用px值。这将导致不同尺寸的手机出现不良行为。请看@Flavio:无论如何,我认为你的问题在于你的内部视图比你在RL中给他们的区域要大。我相信通过制定尺寸标准,它应该会起作用。如果我将其应用于儿童视图,它们将比我想要的更大。我想要它们的大小,列表项跨越100dp。我使用LinearLayout水平集中progressbar/textview对。不,内部视图的高度只是一个小文本的大小。当我试图设置一个比100dp大得多的值时,这没有什么区别。我认为问题是因为此布局被设置为ListView项。ListView不允许我设置所需的高度。请尝试向RelativeLayout添加背景,以确保它确实正在包装,同时尝试将高度增加到200度,以查看发生的情况。调试布局的一个好工具是“工具”文件夹中的“继承者查看器”。这可能有助于向你展示什么在驱动什么。Faria还有,你想要的行为是什么?也许你应该把它放在一个高度为100的滚动视图中?我真的不知道你为什么想要一个部分被切断的布局。谢谢你,德巴拉蒂。检查下面的屏幕截图。第一个显示了一个列表,最后有一个“加载”项。我发布的XML对应于此加载项的XML。第二个屏幕截图显示了当我按照您建议的方式更改XML时会发生什么。这不是我想要的。我想要的是增加列表项的高度,而不增加textView或progressbar的大小。我认为唯一的方法是增加外部视图组的高度。如果我从100dp更改为500或1000dp或任何更高的值,列表项将保持相同的大小。