繁体   English   中英

通过网格/列表视图推离屏幕的视图

[英]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>

我已经体验过LinearLayoutRelativeLayout更快,更健壮,但这是一种个人选择。

这应该做你的工作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM