![](/img/trans.png)
[英]Android: ScrollView keeps wrapping the content instead of using layout_height
[英]layout_height always wrapping content
這只是一個簡單的問題:
我有一個布局文件,它作為ListView中的項目呈現。 我將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>
這樣做:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="100dip">
我認為在列表視圖中所有項目都具有相同的高度。 在您的情況下,您可以在列表頁腳視圖中添加進度條。 在ListItemSubtext之前或之后添加虛擬高度調整器。 嘗試使用TableLayout而不是相對和線性布局。
虛擬調節器就是這樣的。
<View android:layout_width="wrap_content" android:layout_height="100dip"/>
請注意,每個元素都不需要xmlns。
嘗試使用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>
如果這對您不起作用,請說明您想要做什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.