1

2つのボタンが存在するカメラレイアウトを作りました。clickボタンとshareボタン。

問題は、このボタンを同じビューに揃えたいのですが、できません。

これはボタンの私のコードです

<Button
    android:id="@+id/buttonClick"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Click"
    android:layout_gravity="left" />

<Button
    android:id="@+id/buttonShare"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Share"
    android:layout_gravity="right" />

ここに画像の説明を入力

しかし、私はclickボタンがボタンと同じ場所になることを望んでいshareます...

4

4 に答える 4

2

おそらくLinearLayout、他のビューに沿ってそれらを持っています(「カメラデモ」テキスト付き)。しかし、完全なレイアウト ファイルを表示しなくても、次のような別のレイアウトでそれらをラップできます。

<RelativeLayout    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<Button
    android:id="@+id/buttonClick"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Click"
    android:layout_alignParentLeft="true" />

<Button
    android:id="@+id/buttonShare"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Share"
    android:layout_alignParentRight="true" />
</RelativeLayout>
于 2012-06-21T05:44:40.687 に答える
1

あなたのイメージから、あなたの親レイアウトは垂直方向の LinearLayout を使用しています。したがって、追加した各ビューは、垂直方向に 1 つずつ配置されます。

2 つのボタンを同じ行に配置する場合は、RelativeLayout を使用してこれら 2 つのボタンをラップする必要があります。そして子をRelativeLayoutの左右に配置します

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

    <Button
        android:id="@+id/buttonShare"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Share" />

    <Button
        android:id="@+id/buttonClick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Click" />

</RelativeLayout>
于 2012-06-21T05:45:52.077 に答える
1
 <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
             >

            <Button
                android:id="@+id/buttonClick"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:text="Click" />

            <Button
                android:id="@+id/buttonShare"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="Share" />
        </RelativeLayout>

should have one more RelativeLayout as parent of all....

ここに画像の説明を入力

私がコンプリートとして作ったもの..

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

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
         >

        <Button
            android:id="@+id/buttonClick"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="Click" />

        <Button
            android:id="@+id/buttonShare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="Share" />
    </RelativeLayout>

</RelativeLayout>
于 2012-06-21T05:47:15.197 に答える
0

レイアウトをよりよく理解するには、このレイアウトに従ってください

ここ。そしてあなたの質問によると、相対レイアウトをよりよく使用してください

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" //to assign botton to bottom of layout
     >
于 2012-11-08T04:50:39.967 に答える