2011-12-02 37 views
0

我目前正在开发一个Android应用程序,并且我有一个关于布局的问题。在我的XML布局文件中,我创建了一个相对布局(fill_parent的宽度和wrap_content的高度),其中包含一个列表视图(或可能是一个消耗性的列表视图 - fill_parent高度和宽度)。在相应的activity的onCreate方法中,我只需将对应于我的列表的适配器设置并将其附加到我的列表中。问题是,当我运行我的应用程序相对布局只有93dip的大小,所以它隐藏我的列表,其大小从67到210dip当我想相对布局高度坚持列表当前大小(大小在创建或恢复活动时可能不会通过活动中的操作进行更改)。有谁会有解决方案的想法来解决这个问题吗?设置包含listView的相对布局的高度

因为问了一些代码:

<LinearLayout android:id="@+id/content" 
       android:layout_width="fill_parent" 
       android:background="@drawable/row" 
       android:layout_below="@+id/header" 
       android:layout_height="wrap_content"> 
     <ListView android:id="@+id/list" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@drawable/listrow"/> 
</LinearLayout> 

并在Java文件(其中snapRecords是我的对象列表):

m_panel = (RelativeLayout)findViewById(R.id.lastFareRecordPanel); 
ListView lv = (ListView)m_panel.findViewById(R.id.list); 
final QuickSnapBookmarksAdapter adapter = new QuickSnapBookmarksAdapter(snapRecords, getApplicationContext(), this, lv); 
lv.setAdapter(adapter); 

提前感谢您的帮助!

贝尼亚

+2

你可以添加的布局和一些代码吗? –

+1

你为什么不使用LinearLayout?在你的项目中使用RelativeLayout有什么特别的理由吗? – Jayabal

+0

那么,理论上我可以修改它,但我宁愿不这样做,因为那意味着对我来说会有很多变化,但对于其他从事项目工作的人也是如此......如果我真的需要,但我首先想要知道如果解决方案可能存在与我的问题相对布局... – Ben

回答

0

我有一个类似的situation.When我改变父布局到LinearLayout中,它working.Here是代码:

<?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:background="#FFFFFF" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/LinearLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <ImageButton 
      android:id="@+id/prev" 
      android:layout_width="106dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="@null" 
      android:onClick="prev" 
      android:paddingTop="8dip" 
      android:src="@drawable/previous" > 
     </ImageButton> 

     <ImageButton 
      android:id="@+id/next" 
      android:layout_width="106dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="@null" 
      android:onClick="next" 
      android:paddingTop="8dip" 
      android:src="@drawable/next" > 
     </ImageButton> 

     <ImageButton 
      android:id="@+id/Logout" 
      android:layout_width="106dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="@null" 
      android:onClick="logout" 
      android:paddingTop="8dip" 
      android:src="@drawable/logout1" 
      android:text="@string/Logout" > 
     </ImageButton> 
    </LinearLayout> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="wrap_content" 
     android:layout_height="330dip" > 
    </ListView> 

    <TextView 
     android:id="@android:id/empty" 
     android:layout_width="fill_parent" 
     android:layout_height="338dip" 
     android:text="@string/EmptyList" 
     android:textSize="35dip" /> 

    <LinearLayout 
     android:id="@+id/LinearLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <ImageButton 
      android:id="@+id/prev1" 
      android:layout_width="106dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="@null" 
      android:onClick="prev" 
      android:src="@drawable/previous" > 
     </ImageButton> 

     <ImageButton 
      android:id="@+id/next1" 
      android:layout_width="106dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="@null" 
      android:onClick="next" 
      android:src="@drawable/next" > 
     </ImageButton> 

     <ImageButton 
      android:id="@+id/Logout" 
      android:layout_width="106dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:background="@null" 
      android:onClick="logout" 
      android:src="@drawable/logout1" 
      android:text="@string/Logout" > 
     </ImageButton> 
    </LinearLayout> 

</LinearLayout> 
+0

你解决了这个问题吗? – freshDroid

+0

对不起,我在为我的问题添加一些代码的同时测试了您的解决方案...但不是...在我的情况下不起作用...完全相同的问题... – Ben

+0

除列表之外是否还有其他视图视图?尝试删除父布局,如果listview是唯一的孩子... – freshDroid