0

アクションバーに画像ボタンを表示するカスタムテーマを作成しました。Androidでこれらのボタンを垂直方向に中央揃えする方法を考えていました。

これまでに書いたコード。

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

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|left|center_vertical"
        android:background="@drawable/groups" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center|fill_vertical"
        android:background="@drawable/contactlist" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|right|center_vertical"
        android:background="@drawable/favourites" />

</FrameLayout>

これは私が欲しいものです

ここに画像の説明を入力

4

3 に答える 3

0

画像ボタンLinearLayoutを垂直方向に配置して、重力をandroid:layout_gravity="center"

于 2013-09-19T03:38:52.090 に答える
0

このコードに従ってください。

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

    <ImageButton
        android:layout_width="0dip"
        android:layout_height="50dip"
        android:layout_gravity="top|left|center_vertical"
        android:layout_weight="1"
        android:background="#FE6602" />

    <ImageButton
        android:layout_width="0dip"
        android:layout_height="50dip"
        android:layout_gravity="top|center|fill_vertical"
        android:layout_weight="1"
        android:background="#DBEAF9" />

    <ImageButton
        android:layout_width="0dip"
        android:layout_height="50dip"
        android:layout_gravity="top|right|center_vertical"
        android:layout_weight="1"
        android:background="#FAF2B0" />

</LinearLayout>

変更点:

android:layout_height="50dip" to  android:layout_height="wrap_content"

android:background="#FE6602" to android:background="@drawable/contactlist"

シンプルな色と静的なサイズまたはテスト目的の作品をチャームのように配置するだけです。

于 2013-09-19T04:37:57.417 に答える
0
// try this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:background="@android:color/holo_blue_dark"
            android:padding="5dp"
            android:layout_weight="1">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/groups" />

        </LinearLayout>
        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@android:color/white"/>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:background="@android:color/holo_blue_dark"
            android:padding="5dp"
            android:layout_weight="1">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/contactlist" />

        </LinearLayout>
        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@android:color/white"/>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:background="@android:color/holo_blue_dark"
            android:padding="5dp"
            android:layout_weight="1">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/favourites" />

        </LinearLayout>
    </LinearLayout>
</FrameLayout>
于 2013-09-19T04:09:35.130 に答える