1

私は3つのボタンを持っているので、いくつかのサイズがあります.4番目のボタンを2番目のボタンの下に置き、4番目のボタンの中心を2番目のボタンの中心に合わせる必要があります.

私はそれを行うのに少し問題があります。何かアイデアはありますか?

 

!---!---!---!
! ! ! !
!---!---!---!
  !-------!
  ! !
  !-------!

私は重力で遊んでいて、中心などを揃えていますが、それでも必要なものを見つけることができませんでした。これは、あと数行ないと投稿できません。この行を追加すると違いが生じるのだろうか?

4

5 に答える 5

1

ここにコードがあります

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/top_buttons"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="First" />

        <Button
            android:id="@+id/button_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Second" />

        <Button
            android:id="@+id/button_3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Third" />
    </LinearLayout>

    <Button
        android:id="@+id/button_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/top_buttons"
        android:layout_centerHorizontal="true"
        android:text="Forth" />
</RelativeLayout>
于 2013-08-14T03:06:42.410 に答える
0

多分あなたはこれを試すことができます:

同じ幅の 2 つの LinearLayouts を作成します。最初の 3 つのボタンを最初の LinearLayout に配置し、4 番目のボタンを 2 つ目の LinearLayout に配置します。android:gravity="center"2 番目の LinearLayoutに追加します。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:id="@+id/layout1">

        <Button
            android:id="@+id/button1"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:text="B1" />
        <Button
            android:id="@+id/button2"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:text="B2" />
        <Button
            android:id="@+id/button3"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:text="B3" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="150dp"
        android:layout_height="wrap_content" 
        android:layout_below="@id/layout1"
        android:gravity="center"
        >

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button2" 
            android:layout_gravity="center"
            />

    </LinearLayout>

</RelativeLayout>
于 2013-08-14T03:13:20.967 に答える
0

このコードを試してください。これで問題が解決します。お力になれて、嬉しいです

 <LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

<LinearLayout
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Button" />
</LinearLayout>

</LinearLayout>
于 2013-08-14T10:04:26.827 に答える