简体   繁体   English

Android安排布局

[英]Android arranging layouts

Well basically I'm making an app which needs something like an action bar, 4 buttons bellow that and a listview on the rest of the screen. 好吧,基本上,我正在制作一个需要诸如操作栏,下面有4个按钮以及屏幕其余部分上的列表视图之类的应用。 But I'm stuck at how to arrange them, since I'm also using a navigation drawer. 但是我仍然在如何安排它们,因为我还使用了导航抽屉。

This is how it's supossed to look: 看起来像这样: lookalikeApp

The problem is that I have no idea how to arrange them properly I did this but I know it's wrong and it's still missing the actionbar like header: 问题是我不知道如何正确地排列它们,但是我知道这是错误的,并且仍然缺少标题栏等动作栏:

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

<LinearLayout
    android:id="@+id/menu"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/btnFormatos"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/b_formato"
            android:onClick="formatos"
            android:contentDescription="@string/desc"
             />

        <ImageButton
            android:id="@+id/btnTiendas"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/b_tiendas"
            android:onClick="tiendas"
            android:contentDescription="@string/desc"
             />
         <ImageButton
            android:id="@+id/btnMarcas"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/b_marcas"
            android:onClick="marcas"
            android:contentDescription="@string/desc"
             />

          <ImageButton
            android:id="@+id/btnGiros"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/b_categorias"
            android:onClick="categorias"
            android:contentDescription="@string/desc"
             />

          <ImageButton
            android:id="@+id/btnOrdenar"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/b_ordenar"
            android:onClick="ordenar"
            android:contentDescription="@string/desc"
             />
</LinearLayout>

<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="#b5b5b5"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_selector"
    android:translationY="70dp"
    android:layout_weight="1"
    />
<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#111"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>

Not to mention that with translateY on my listView when I get to the bottom of the list I can't see the last item. 更不用说当我到达列表底部时,在listView上使用translateY时,我看不到最后一项。

I know I'm supossed to be using fragments and I'm looking into that but that won't solve my initial problem so any help would be appreciated. 我知道应该使用片段,但我正在调查,但这不能解决我的最初问题,因此,我们将不胜感激。

Thank you for your time 感谢您的时间

Update your xml file as per code below 按照下面的代码更新您的xml文件

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

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

           <LinearLayout
               android:id="@+id/menu"
               android:layout_width="match_parent"
               android:layout_height="70dp"
     android:orientation="horizontal" >

                <ImageButton
                    android:id="@+id/btnFormatos"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:src="@drawable/b_formato"
                    android:onClick="formatos"
                    android:contentDescription="@string/desc"
                     />

                <ImageButton
                    android:id="@+id/btnTiendas"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:src="@drawable/b_tiendas"
                    android:onClick="tiendas"
                    android:contentDescription="@string/desc"
                     />
                 <ImageButton
                    android:id="@+id/btnMarcas"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:src="@drawable/b_marcas"
                    android:onClick="marcas"
                    android:contentDescription="@string/desc"
                     />

                  <ImageButton
                    android:id="@+id/btnGiros"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:src="@drawable/b_categorias"
                    android:onClick="categorias"
                    android:contentDescription="@string/desc"
                     />

                  <ImageButton
                    android:id="@+id/btnOrdenar"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:src="@drawable/b_ordenar"
                    android:onClick="ordenar"
                    android:contentDescription="@string/desc"
                     />
           </LinearLayout>

           <ListView
               android:id="@+id/list"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:divider="#b5b5b5"
               android:dividerHeight="1dp" 
               android:listSelector="@drawable/list_selector"
               android:layout_marginTop="70dp"
               android:layout_weight="1"
               />

       </FrameLayout>


            <ListView
             android:id="@+id/left_drawer"
             android:layout_width="240dp"
             android:layout_height="match_parent"
             android:layout_gravity="start"
             android:background="#111"
             android:choiceMode="singleChoice"
             android:divider="@android:color/transparent"
             android:dividerHeight="0dp" />
 </android.support.v4.widget.DrawerLayout>

Try and enjoy. 尝试并享受。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM