2013-06-11 58 views
0

我试图让ListView保持相同的大小,即使它溢出。但是,一旦ListView溢出,它会将屏幕下方的按钮按下。我如何防止它推动其下的其他元素?ListView将按钮按下屏幕

正如你可以从上面的图片看,第二个显示的按钮被推离屏幕一次ListView控件溢出。

XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:background="@color/splash_bg" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<LinearLayout 
    android:background="@color/splash_bg" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:padding="10dp" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/subtitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textSize="20sp" 
     android:paddingBottom="10dp" 
     android:textColor="@color/splash_text" 
     android:text="@string/sub" /> 

    <EditText 
     android:id="@+id/grp_name" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/field1" 
     android:lines="1" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/members" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:textSize="15sp" 
      android:paddingTop="5dp" 
      android:textColor="@color/splash_text" 
      android:text="@string/members" /> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@color/splash_bg" 
      android:orientation="horizontal" > 

      <EditText 
       android:id="@+id/name" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:hint="@string/field2" /> 

      <Button 
       android:id="@+id/add" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/add" /> 

     </LinearLayout> 

     <ListView 
      android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:background="@color/splash_bg" /> 

    </LinearLayout> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="bottom" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:paddingBottom="5dp" 
    android:paddingTop="10dp" > 

    <Button 
     android:id="@+id/save_btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="5" 
     android:text="Save" /> 

    <Button 
     android:id="@+id/cancel_btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Cancel" /> 

</LinearLayout> 

回答

7

Changet

<ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="5dp" 
     android:background="@color/splash_bg" /> 

<ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" 
     android:paddingLeft="5dp" 
     android:background="@color/splash_bg" /> 
+0

你为什么不使用一个相对布局,而不是线性布局不工作 – jl90

+0

@ jl90?试试我的答案并修改相同的 – Raghunandan

+0

@ jl90你试过我的答案吗? – Raghunandan

2

您可以使用此相对布局。修改下面根据您的需要

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center_vertical" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginRight="11dp" 
     android:layout_marginTop="11dp" 
     android:text="Create New Group" /> 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_below="@+id/textView1" 
     android:layout_marginTop="23dp" 
     android:ems="10" 
     android:inputType="textPersonName" > 

     <requestFocus /> 
    </EditText> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/editText1" 
     android:layout_marginLeft="11dp" 
     android:layout_marginTop="18dp" 
     android:text="Members" /> 

    <EditText 
     android:id="@+id/editText2" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignRight="@+id/textView1" 
     android:layout_below="@+id/textView2" 
     android:layout_marginTop="31dp" 
     android:ems="10" /> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_above="@+id/button1" 
     android:layout_below="@+id/editText2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="5dp" 
     /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/editText2" 
     android:layout_alignBottom="@+id/editText2" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="13dp" 
     android:text="ADD" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/button3" 
     android:layout_below="@android:id/list" 
     android:text="Cancel" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_toLeftOf="@+id/textView1" 
     android:text="Save" /> 

</RelativeLayout> 

enter image description here

-1

我加入这一行:android:layout_weight="1"到的LinearLayout其中存在的EditText(我的问题的根源),问题就消失了!
看看代码,我评论<!-- HERE!!! -->


大声笑我知道我很晚回答这个问答,,对不起,,但任何人谁仍在努力!

enter image description here


<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_horizontal"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:id="@+id/linearLayout1"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="ID : " 
      android:layout_margin="@dimen/EdgeMargins"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="number" 
      android:ems="10" 
      android:id="@+id/editText" 
      android:layout_margin="@dimen/EdgeMargins"/> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:id="@+id/linearLayout2" 
     android:layout_weight="1"> <!-- HERE!!! --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Any Notes :" 
      android:id="@+id/textView2" 
      android:layout_margin="@dimen/EdgeMargins"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/editText2" 
      android:layout_margin="@dimen/EdgeMargins" /> 

    </LinearLayout> 

     <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Done" 
     android:id="@+id/button" 
     android:layout_margin="@dimen/EdgeMargins" /> 

</LinearLayout> 


我有我的问题与突出的EditText在PIC ,,,它以输入的文本扩展和推动完成按钮下来!
我知道我的解决方案可能看起来很愚蠢,但我花了一整天的时间来解决这个问题!

希望它可以帮助^ _^GL