簡體   English   中英

Android - UI元素關閉屏幕

[英]Android - UI Elements going off screen

我在定位布局元素時遇到問題。 我的TableLayout中的AutoComplete和它之后的按鈕正在擴展TableRow大於屏幕的寬度。 任何人都知道為什么? 下面是我的XML代碼以及問題的圖片。

提前致謝!!

<?xml version="1.0" encoding="utf-8"?>

<TableRow android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <AutoCompleteTextView android:id="@+id/installation"
        android:textSize="14sp" android:completionThreshold="3" />
</TableRow>
<TableRow android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button android:id="@+id/btn_find" android:text="@string/btn_find"></Button>
</TableRow>
<TableRow android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/error" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:paddingTop="20px"
        android:textColor="#FF0000" />
</TableRow>

UI的圖片

對於需要表格布局的那些,請使用layout_weight選項。 見下面的代碼。

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="6sp" android:id="@+id/detailsLayout">
            <TableRow
                android:layout_width="wrap_content"
                android:id="@+id/TableRow03"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/TextView06"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="Detail 1"></TextView>
                <TextView
                    android:text="@string/empty_value"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:id="@+id/sessionAudience"
                    android:layout_weight="1"></TextView>
            </TableRow>
         </TableLayout>

默認情況下, TableRow小部件具有android:layout_width="wrap_content" 這並不限制你的屏幕大小 - wrap_content意味着“包裝內容”,而不是“包裝內容,但如果你不介意,請不要離開屏幕的邊緣”。

在這種情況下,您不需要使用TableLayoutTableRows集,因為您沒有表。

因此,一種方法是使用RelativeLayout並讓你的AutoCompleteTextView使用android:layout_alignParentLeft="true"android:layout_alignParentRight="true" 這會將它固定到RelativeLayout的外邊緣,你可以用android:layout_width=fill_parent來填充屏幕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM