简体   繁体   English

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

[英]View pushed off screen by Grid / List View

I already did some research on that question, found some topic but nothing that helped me. 我已经对该问题进行了一些研究,发现了一些话题,但没有任何帮助。

This is what I have : 这就是我所拥有的:

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

The problem I have is that when there are too many elements in my grid, the edittext is pushed off the screen. 我的问题是,当网格中的元素过多时,edittext将被推离屏幕。 I tried to use alignParentBottom on the editText but this is not what I want. 我试图在editText上使用alignParentBottom,但这不是我想要的。

I was wondering if there is any way to keep the edit text always visible even if there are many elements in the grid view AND to keep the edit text below the grid and not aligned bottom with the parent. 我想知道是否有任何方法可以使编辑文本始终可见,即使在网格视图中有很多元素,并且可以将编辑文本保持在网格下方且底部与父对象不对齐。 I also tried to use a scroll view instead of the relative layout... but this is wrong too cause there are too many bugs using a grid view inside a scroll view. 我也尝试使用滚动视图而不是相对布局...但是这也是错误的,因为在滚动视图中使用网格视图存在太多错误。

I hope that I'm clear, don't hesitate to ask for more information. 我希望我很清楚,不要犹豫,索取更多信息。

Thanks you 谢谢

You can achieve this with a simple LinearLayout too: 您也可以使用简单的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>

I've experienced LinearLayout to be faster and more robust then RelativeLayout but that's more kind of personal opnion. 我已经体验过LinearLayoutRelativeLayout更快,更健壮,但这是一种个人选择。

This should do your job. 这应该做你的工作。

<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