2015-07-27 9 views
12

Der Versuch, eine Fußzeile zu einer Navigationsleiste hinzuzufügen, die aus zwei Listen besteht. Ich bin dieses Recht nicht zu tun, habe ich verstanden, dass alles, was ich in der Navigationsleiste möchte, sollte ich einen Boden Layout hinzufügen möchten imUnteres Layout einer Navigationsschublade Android

<LinearLayout 
      android:id="@+id/left_drawer_layout" 

eingekapselt werden, die nicht auf Listview Scroll abhängt. Ich habe verschiedene Versionen von wo versucht, den unteren Layout-Code, aber nichts passiert. Ich brauche ein extra Auge, bitte. Vielen Dank.

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white"> 

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

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/toolbar”/> 



     <!-- Framelayout to display Fragments --> 

     <FrameLayout 
      android:id="@+id/frame_container" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

    </LinearLayout> 


    <!-- Listview to display slider menu --> 

    <LinearLayout 
     android:id="@+id/left_drawer_layout" 
     android:layout_width="@dimen/navigation_drawer_max_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:orientation="vertical"> 


     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="48dp" 
      android:background="@color/list_background"> 

      <Button 
       android:id="@+id/refreshBtn" 
       android:layout_width="match_parent" 
       android:layout_height="48dp" 
       android:text="@string/refresh" 
       android:visibility="gone" /> 

      <EditText 
       android:id="@+id/searchMenuTxt" 
       android:layout_width="match_parent" 
       android:layout_height="48dp" 
       android:background="@color/list_background_pressed" 
       android:drawableLeft="@drawable/search_web" 
       android:drawablePadding="@dimen/activity_horizontal_margin" 
       android:drawableStart="@drawable/search_web" 
       android:focusable="false" 
       android:focusableInTouchMode="true" 
       android:hint="@string/search" 
       android:paddingLeft="8dp" 
       android:singleLine="true" 
       android:textColorHint="@android:color/darker_gray" 
       android:textSize="@dimen/text_size_14"></EditText> 

      <Button 
       android:id="@+id/clearBtn" 
       android:layout_width="24dp" 
       android:layout_height="24dp" 
       android:layout_gravity="right|center" 
       android:background="@drawable/mob_clear" 
       android:paddingRight="8dp" 
       android:visibility="invisible" /> 

     </FrameLayout> 

     <LinearLayout 
      android:id="@+id/left_drawer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <ListView 
       android:id="@+id/activeChatsList" 
       android:layout_width="@dimen/navigation_drawer_max_width" 
       android:layout_height="wrap_content" 
       android:layout_gravity="start" 
       android:background="@color/list_background_pressed" 
       android:choiceMode="singleChoice" 
       android:divider="@drawable/list_divider" 
       android:dividerHeight="1dp" 
       android:fadeScrollbars="false" 
       android:fastScrollEnabled="false" /> 

      <ListView 
       android:id="@+id/drawerListView" 
       android:layout_width="@dimen/navigation_drawer_max_width" 
       android:layout_height="match_parent" 
       android:layout_gravity="start" 
       android:background="@drawable/list_selector" 
       android:choiceMode="singleChoice" 
       android:divider="@drawable/list_divider" 
       android:dividerHeight="1dp" 
       android:drawSelectorOnTop="true" 
       android:fastScrollEnabled="false" 
       android:minHeight="250dp" /> 
      <LinearLayout 
       android:layout_width="fill_parent" android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:layout_alignParentBottom="true"> 

       <Button android:id="@+id/CancelButton" android:layout_width="wrap_content" 
        android:layout_height="wrap_content" android:text=“Profile" /> 
       > 

      </LinearLayout> 
     </LinearLayout> 


    </LinearLayout> 

</android.support.v4.widget.DrawerLayout> 
+0

vielleicht, weil Ihr drawerListView –

+0

match_parent Höhe hatte nicht den Trick – user1140656

+0

Haben Sie die Taste wollen ganz gleich, an der Unterseite der Schublade Widget festgelegt werden, wie groß die Listviews sind? Außerdem ist es selten sinnvoll, zwei ListViews nacheinander zu verwenden. – Luksprog

Antwort

3

Sie können die Grundidee aus diesem Code-Snippet haben. Und Android hat jetzt die eingebaute Funktionalität für Menü Schublade. Was Sie versuchen, ist ein alter Ansatz. Aktionsleisten-Sherlock ist veraltet. Daher würde ich Ihnen empfehlen, zu AppCompat zu wechseln. Mit Appcompat folgt der Code für das Layout der Menüleiste zusammen mit der Fußzeile.

Schublade_Fragment.

xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res/com.focial" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/transparent" > 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" > 

    <LinearLayout 
     android:id="@+id/footer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     android:clickable="true" 
     android:background="@android:color/black" 
     android:orientation="vertical"> 

    <!-- any addition stuff you want in yoour footer layout --> 

    </LinearLayout> 

    <ListView 
     android:id="@+id/drawer_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/footer" 
     android:choiceMode="singleChoice" 
     android:dividerHeight="1dp" /> 
</RelativeLayout> 

activity_home.xml (wo Sie wollen/show Schublade ermöglichen)

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/white" > 

<FrameLayout 
    android:id="@+id/realcontent" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<fragment 
    android:id="@+id/navigation_drawer" 
    android:name="com.focial.fragment.NavigationDrawerFragment" 
    android:layout_width="@dimen/navigation_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" /> 

HomeActivity.java

private NavigationDrawerFragment mNavigationDrawerFragment; 
private ArrayList<DrawerItem> drawerItems; 
private DrawerLayout drawerLayout; 

protected void initUIComponents() { 
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); 
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, drawerLayout, drawerItems); 
} 

@Override 
public void onNavigationDrawerItemSelected(int itemlabelId) { 
    FragmentManager fragmentManager = getSupportFragmentManager(); 
    fragmentManager.beginTransaction().replace(R.id.realcontent, CustomFragmentManager.newInstance(itemlabelId)).commit(); 
} 

NavigationDrawerFragment .java

View rootView = (RelativeLayout) inflater.inflate(R.layout.layout_fragment_drawer, container, false); 
ListView mDrawerListView = (ListView) rootView.findViewById(R.id.drawer_list); 
    LinearLayout footerView = (LinearLayout) rootView.findViewById(R.id.footer); 
0

Ihre linke Schublade Layout muss nicht unbedingt ein LinearLayout sein, könnte es sein, so etwas wie:

<RelativeLayout 
    android:id="@+id/left_drawer_layout" 
    android:layout_width="@dimen/navigation_drawer_max_width" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/drawer_footer" 
     android:layout_gravity="start" 
     android:orientation="vertical"> 

     <!-- YOUR PREVIOUS LAYOUT --> 
    </LinearLayout> 

    <LinearLayout 
     android.id="@+id/drawer_footer" 
     android:layout_width="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_height="100dp"> 
     <!-- YOUR FOOTER WITH layout_alignParentBottom --> 
    </LinearLayout> 
</RelativeLayout> 

Auf diese Weise Ihre Fußzeile wird auf der Unterseite der linken Schublade immer sein.

+0

Betrachten Sie stattdessen ein FrameLayout und verwenden Sie die Schwerkraft für eine bessere Leistung. Das RelativeLayout ist teuer, da es zweimal misst. – JohanShogun

-1

Sie müssen Frame-Layout nach der Schublade Steuerelement Tag verwenden.

Legen Sie alle Steuerelemente in das Rahmenlayout.

+0

Bitte geben Sie ein Beispiel für Ihre Antwort, und auch, warum das so sein muss ... –

0

Da Ihre drawerListView 's android:layout_height="match_parent", so ist es die gesamte Höhe in Geröll und drücken Sie die untere Layout aus dem Bildschirm.
Sie können dies versuchen:

<LinearLayout 
android:id="@+id/left_drawer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/activeChatsList" /> 

    <ListView 
     android:id="@+id/drawerListView" /> 
</LinearLayout> 

<Button 
    android:id="@+id/CancelButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="“Profile" /> 

</LinearLayout> 

Neben der, dass, empfehle ich Ihnen 1 Listenansicht mit Multiviewtype in Adapter anstelle von 2 separaten Listenansichten, weil 1. scrollbaren wenn das wird die zweite verwenden sollte dann nicht angezeigt oder Wenn der 2. angezeigt wird, bedeutet das, dass der 1. nicht scrollen muss, so dass es sinnlos ist, ein Listenansicht zu sein.
Hop das hilft.

0

Am besten erstellen Sie ein anderes Layout für die Fußzeile und fügen dieses Layout zu Ihrer Fußzeile hinzu.

listView.addFooterView(R.layout.<your footer layout>); 
0

Dies ist nur ein Vorschlag. Ich füge das als meine Antwort hinzu, weil ich nicht genug Ruf habe, um einen Kommentar zu anderen Beiträgen hinzuzufügen, Sorry. Ich denke, das ist bereits in SO gelöst. Bitte überprüfen Sie die unter diesem Link How to put list items at the bottom of list view in Navigation Drawer like Foursquare

+0

können Sie bitte einige Beispielbildschirme hinzufügen, damit Sie es besser betrachten können. –

0

können Sie ActionBarSherlock-Bibliothek verwenden. Ich denke, es ist so hilfreich.

Verwandte Themen