2015-02-21 1 views
0

Я создал этот макет для моего ListView:Создание макета для ListView со списком боковой индекс

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

    <ListView 
     android:id="@+id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:dividerHeight="10.0sp" 
     android:background="#4a4c4d"> 
    </ListView> 

    <LinearLayout android:orientation="vertical" 
     android:layout_width="28dip" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:background="@android:color/transparent" > 

     <TextView android:id="@+id/A" 
      android:text="A" 
      android:tag="A" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
     <TextView android:id="@+id/B" 
      android:text="B" 
      android:tag="B" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/C" 
      android:text="C" 
      android:tag="C" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/D" 
      android:text="D" 
      android:tag="D" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/E" 
      android:text="E" 
      android:tag="E" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/F" 
      android:text="F" 
      android:tag="F" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/G" 
      android:text="G" 
      android:tag="G" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/H" 
      android:text="H" 
      android:tag="H" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/I" 
      android:text="I" 
      android:tag="I" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/J" 
      android:text="J" 
      android:tag="J" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/K" 
      android:text="K" 
      android:tag="K" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/L" 
      android:text="L" 
      android:tag="L" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/M" 
      android:text="M" 
      android:tag="M" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/N" 
      android:text="N" 
      android:tag="N" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/O" 
      android:text="O" 
      android:tag="O" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/P" 
      android:text="P" 
      android:tag="P" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/Q" 
      android:text="Q" 
      android:tag="Q" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/R" 
      android:text="R" 
      android:tag="R" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/S" 
      android:text="S" 
      android:tag="S" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/T" 
      android:text="T" 
      android:tag="T" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/U" 
      android:text="U" 
      android:tag="U" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/V" 
      android:text="V" 
      android:tag="V" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/W" 
      android:text="W" 
      android:tag="W" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/X" 
      android:text="X" 
      android:tag="X" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/Y" 
      android:text="Y" 
      android:tag="Y" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
     <TextView android:id="@+id/Z" 
      android:text="Z" 
      android:tag="Z" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 
</RelativeLayout> 

Но вертикальная LinearLayout появляется перекрываться ListView вместо того, чтобы быть в праве ListView. Как исправить этот вышеприведенный код, чтобы иметь ListView слева (который охватывает около 90% экрана) и вертикальный LinearLayout справа (покрытие оставшихся 10% экрана)?

Заранее спасибо за помощь

ответ

1

Использование LinearLayout вместо RelativeLayout.

Держите ориентацию корня LinearLayout горизонтальной, а затем создать 2 linearLaytout внутри него один с weight="0.9" другой с weight="0.1"

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

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.9"> 

     <ListView 
      android:id="@+id/android:list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:dividerHeight="10.0sp" 
      android:background="#4a4c4d"> 
     </ListView> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.1"> 
     <TextView .../> 
     <TextView .../> 
     <TextView .../> 
     . 
     . 
     . 
    </LinearLayout> 
</LinearLayout> 
1

Вы должны использовать LinearLayout в качестве родительского макета, а не RelativeLayout. Также назначьте свойство макета веса для покрытия части экрана Android. Надеюсь, этот код работает для вас.

enter code here 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent"` 
    android:layout_height="match_parent" > 

    <ListView 
     android:id="@+id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#4a4c4d" 
     android:layout_weight=".9" 
     android:dividerHeight="10.0sp" > 
    </ListView> 

    <LinearLayout 
     android:layout_width="28dip" 
     android:layout_height="wrap_content" 
     android:layout_weight=".1" 
     android:background="@android:color/transparent" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/A" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="A" 
      android:text="A" /> 

     <TextView 
      android:id="@+id/B" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="B" 
      android:text="B" /> 

     <TextView 
      android:id="@+id/C" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="C" 
      android:text="C" /> 

     <TextView 
      android:id="@+id/D" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="D" 
      android:text="D" /> 

     <TextView 
      android:id="@+id/E" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="E" 
      android:text="E" /> 

     <TextView 
      android:id="@+id/F" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="F" 
      android:text="F" /> 

     <TextView 
      android:id="@+id/G" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="G" 
      android:text="G" /> 

     <TextView 
      android:id="@+id/H" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="H" 
      android:text="H" /> 

     <TextView 
      android:id="@+id/I" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="I" 
      android:text="I" /> 

     <TextView 
      android:id="@+id/J" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="J" 
      android:text="J" /> 

     <TextView 
      android:id="@+id/K" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="K" 
      android:text="K" /> 

     <TextView 
      android:id="@+id/L" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="L" 
      android:text="L" /> 

     <TextView 
      android:id="@+id/M" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="M" 
      android:text="M" /> 

     <TextView 
      android:id="@+id/N" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="N" 
      android:text="N" /> 

     <TextView 
      android:id="@+id/O" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="O" 
      android:text="O" /> 

     <TextView 
      android:id="@+id/P" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="P" 
      android:text="P" /> 

     <TextView 
      android:id="@+id/Q" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="Q" 
      android:text="Q" /> 

     <TextView 
      android:id="@+id/R" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="R" 
      android:text="R" /> 

     <TextView 
      android:id="@+id/S" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="S" 
      android:text="S" /> 

     <TextView 
      android:id="@+id/T" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="T" 
      android:text="T" /> 

     <TextView 
      android:id="@+id/U" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="U" 
      android:text="U" /> 

     <TextView 
      android:id="@+id/V" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="V" 
      android:text="V" /> 

     <TextView 
      android:id="@+id/W" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="W" 
      android:text="W" /> 

     <TextView 
      android:id="@+id/X" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="X" 
      android:text="X" /> 

     <TextView 
      android:id="@+id/Y" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="Y" 
      android:text="Y" /> 

     <TextView 
      android:id="@+id/Z" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:tag="Z" 
      android:text="Z" /> 
    </LinearLayout> 
</LinearLayout> 
enter code here 
Смежные вопросы