2013-02-28 99 views
1

我有一个列表视图与2个单选按钮项目。当从布局中膨胀时,即使有如下所示的大量空间,它也可以滚动。如屏幕截图所示,我有2个单选按钮。 1.距离 2.评级Android - 列表视图与单选单选按钮

但“评级”单选按钮不可见,我必须滚动才能看到它。这是为什么发生。我试图设置布局高度来包装内容,填充父级和匹配父级。但是这并没有解决问题。任何想法为什么发生这种情况?

我在这里引用列表视图:

ListView radio_list = (ListView) view.findViewById(R.id.RadioList); 
radio_list.setAdapter(new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_single_choice, 
       radio_list_items)); 

radio_list.setItemsCanFocus(true); 
radio_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

我的xml:

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ffffff" 
       android:paddingLeft="10dp" 
       android:text="SEARCH" 
       android:textColor="#FF3300" 
       android:textSize="20dp" > 
      </TextView> 
     </LinearLayout> 

     <RelativeLayout 
      android:id="@+id/searchTextLayout" 
      android:layout_width="match_parent" 
      android:layout_height="50dip" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginBottom="20dip" 
      android:layout_marginLeft="20dip" 
      android:layout_marginRight="20dip" 
      android:layout_marginTop="20dip" 
      android:orientation="horizontal" > 

      <ImageButton 
       android:id="@+id/searchTextButton" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_alignParentLeft="true" 
       android:background="#685E5C" 
       android:contentDescription="Sample" 
       android:scaleType="fitCenter" 
       android:src="@drawable/abs__ic_search" /> 

      <EditText 
       android:id="@+id/searchText" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_toRightOf="@id/searchTextButton" 
       android:background="@drawable/background_black_border_full" 
       android:padding="8dp" 
       android:textColor="@android:color/white" /> 
     </RelativeLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ffffff" 
       android:paddingLeft="10dp" 
       android:text="SORT BY" 
       android:textColor="#FF3300" 
       android:textSize="20dp" > 
      </TextView> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <ListView 
       android:id="@+id/RadioList" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       /> 
     </LinearLayout> 
</LinearLayout> 
+0

是行'的Li​​stView radio_list =(ListView控件)view.findViewById(R.id.RadioList);''从的onCreate()'或别的地方?此外,这里的“视图”是什么? – Barney 2013-02-28 11:45:31

+0

它来自扩展SherlockFragment的我的SlidingFragment类的onCreateView。也“查看视图= inflater.inflate(R.layout.list,容器,假);” – 2013-02-28 11:48:52

+0

我正在构建一个示例应用程序来实现滑动菜单。所以我会返回“视图”到我的SlidingFragmentActivity来显示滑动菜单。 – 2013-02-28 11:53:33

回答

3

您的布局XML文件是怪异,

首先你应该简化它:

LinearLayout =>中没有一个单独的元素,它意味着相应的线性布局是无用的。

第二点:如果线性布局中有两个孩子,并且第一个孩子的高度为“match_parent”而没有设置任何layout_weight,则第二个孩子将被推出,因为没有剩余空间。 (它可能是您的问题)

第三点:您正在使用相对布局作为线性布局,证明是您尝试在其上使用的android:orientation参数。它是无用的。相对布局孩子的位置由它们之间的相对位置给出。在你的情况下,你可以使用LinearLayout和水平方向,而不是RelativeLayout

最好建议来帮助你:简化你的布局xml。

More on this topic.