2013-02-28 121 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.