Android: Evernote style layout

心已入冬 提交于 2019-12-23 04:43:59

问题


I have a layout for the main screen in an app, which I would like to have an evernote style. So far, my code is this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center_vertical|center_horizontal"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button" />

        <ImageButton
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/btn3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button" />

        <ImageButton
            android:id="@+id/btn4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button" />
    </LinearLayout>

</LinearLayout>

This is how it looks like:

And this is how I'd like it to look like:

How could I achieve this? Grouping the buttons like this?

Thanks a lot in advance!


回答1:


You can adapt it to this, this is from the Google I/O app.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:background="#ffffff">
<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_weight="1" 
    android:padding="6dip">
    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_weight="1">
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_weight="1">
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />

    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_weight="1">
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
        <Button android:id="@+id/button" 
            android:text="@string/button"
            android:drawableTop="@drawable/button" />
    </LinearLayout>
</LinearLayout>




回答2:


you just need to set the width of the ImageButtons to 0dp and give them a layout_weight of 1. Furthermore set layout_gravity to center_horizontal.

This will make them center nicely.

Best wishes, Tim



来源:https://stackoverflow.com/questions/10294064/android-evernote-style-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!