2013-07-27 12 views
8

Mam ListView, który zostanie wypełniony AsyncTask i przy dolnej krawędzi okna aplikacji trzeba pokazać stały układ nakładki takiego:Jak utworzyć układ nakładki na pogrupowanych

enter image description here

Ale nie mogę zrozumieć, jak mogę to zrobić w xml? To jest mój obecny layout.xml:

<?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="vertical"> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <!-- Probably I need to do something here --> 

</LinearLayout> 
+0

http://www.curious-creature.org/2009/03/01/android-layout-tricks-3-optimize-part-1/ Weź to :) –

Odpowiedz

9

Zgodnie z sugestią Daniela, użyj RelativeLayout, ponieważ umożliwia on układanie komponentów (tak samo z FrameLayout i SurfaceView). Poniższy kod daje układ, którego szukasz:

<?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/list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:background="@color/transparentBlack" 
    android:layout_alignParentBottom="true" > 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/textView1" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="20dp" 
     android:text="Medium Text" 
     android:textColor="@color/white" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="40dp" 
     android:text="Large Text" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="@color/white" /> 

    </RelativeLayout> 

</RelativeLayout> 

W powyższym kodzie, wartości hex kolor dla transparentBlack jest #95000000 i white jest #ffffff.

Oto doskonały samouczek na temat podstaw projektowania interfejsu użytkownika w Androidzie: Android User Interface Design: Layout Basics.

+1

Dzięki temu doskonale działa! Przeczytam link, który podasz :) –

+1

Co jeśli chcesz przewinąć najbardziej wysunięty element nad przyciskiem nakładki? – l33t

+1

@ l33t Powiedzmy, że używasz 'ArrayList' do przechowywania obiektów listy. Dodaj "puste" element spacera na końcu tej listy. W 'getView()' twojego adaptera => kiedy (pozycja == mArrayList.size-1), ustaw wysokość 'convertView' na' 'overlay's' height => ustaw widoczność convertView na' Widok.INVISIBLE'. Nie próbowałem tego - więc takie podejście może wymagać pewnych modyfikacji. Jeśli chcesz, możesz edytować moją odpowiedź przy końcowej implementacji. – Vikram

2

zmienić układ rodzic RelativeLayout lub FrameLayout i ustawić stały widok na tym samym poziomie ListView (ale po ListView)

coś takiego:

---> RelativeLayout 
    --> ListView 
    --> Any view as the fixed view 

można następnie wyrównać stały widok na dnie zawijania RelativeLayout

<?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/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <!-- Here you should position the fixed view --> 
</RelativeLayout> 
+0

Czy możesz podać przykład kodu? –

Powiązane problemy