[英]View pushed off screen by Grid / List View
我已經對該問題進行了一些研究,發現了一些話題,但沒有任何幫助。
這就是我所擁有的:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<GridView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="2"
android:padding="5dp"/>
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"/>
</RelativeLayout>
我的問題是,當網格中的元素過多時,edittext將被推離屏幕。 我試圖在editText上使用alignParentBottom,但這不是我想要的。
我想知道是否有任何方法可以使編輯文本始終可見,即使在網格視圖中有很多元素,並且可以將編輯文本保持在網格下方且底部與父對象不對齊。 我也嘗試使用滾動視圖而不是相對布局...但是這也是錯誤的,因為在滾動視圖中使用網格視圖存在太多錯誤。
我希望我很清楚,不要猶豫,索取更多信息。
謝謝
您也可以使用簡單的LinearLayout
實現此目的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<GridLayout
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:numColumns="2"
android:padding="5dp" />
<EditText
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:padding="5dp" >
<requestFocus />
</EditText>
</LinearLayout>
我已經體驗過LinearLayout
比RelativeLayout
更快,更健壯,但這是一種個人選擇。
這應該做你的工作。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<GridView
android:id="@+id/grid"
android:layout_width="match_parent"
android:numColumns="2"
android:layout_height="0dp"
android:layout_weight="8"
android:padding="5dp"/>
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/grid"
android:layout_weight="2"
android:padding="5dp"/>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.