0

Androidのタイトルバーにタイトル+ボタンを追加しようとしています。しかし、どういうわけか、私は得ている結果に満足していません. コードに問題がある可能性があります。誰もこれを以前に試しましたか?私の.xmlは以下です

コード.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:background="#484848"
            android:orientation="horizontal">

        <TextView
            android:id="@+id/windowtitle"
            android:layout_width="match_parent"
            android:layout_marginTop="2dip"
            android:layout_height="wrap_content"
            android:text="Support"
            android:gravity="center_horizontal"
            android:textSize="30sp" ></TextView>

        <Button
            android:id="@+id/syncbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="3dip"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:gravity="left"
            android:text="Sync" />

       </RelativeLayout>


    </RelativeLayout>
4

7 に答える 7

2

あなたが直面している正確な問題に言及してください.2つのビューの位置合わせが適切ではないことが問題だと思います. テキスト ビューに対するボタンの相対的な位置をボタン xml に指定できます。

android:layout_toRightOf="@+id/windowtitle"

また、配置をテキストビューに追加します

于 2013-10-31T07:08:53.763 に答える
1

XML を以下のコードに置き換えます。

<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:background="#484848"

            android:orientation="horizontal">

        <TextView
            android:id="@+id/windowtitle"
            android:layout_width="fill_parent"
           android:layout_centerInParent="true"
            android:layout_height="wrap_content"
            android:text="Support"
            android:gravity="center_horizontal|center_vertical"
            android:textSize="30sp" ></TextView>

        <Button
            android:id="@+id/syncbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_marginTop="3dip"
            android:layout_alignParentRight="true"


            android:text="Sync" />

       </RelativeLayout>

</RelativeLayout>

この作品を願って.....

于 2013-10-31T07:04:58.480 に答える
1

これを試して..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:background="#484848">

        <TextView
            android:id="@+id/windowtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Support"
            android:layout_centerHorizontal="true"
            android:textSize="30sp" ></TextView>

        <Button
            android:id="@+id/syncbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="Sync" />

       </RelativeLayout>


    </RelativeLayout>

これが私の画面です

ここに画像の説明を入力

于 2013-10-31T07:07:14.613 に答える
0

windowtitle Textviewandroid:gravity="center_horizontal"から 削除 し、さらに変更幅を に追加します。android:layout_centerInParent="true"wrap_content

同期ボタンボタンに追加android:layout_centerVertical="true"すると、必要はありませんandroid:layout_alignParentTop="true"

それはすべてあなたの意見を中心にしていました。

以下のxmlを確認してください:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="40dip"
        android:background="#484848"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/windowtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginTop="2dip"
            android:text="Support"
            android:textSize="30sp" >
        </TextView>

        <Button
            android:id="@+id/syncbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_gravity="center"
            android:layout_marginTop="3dip"
            android:gravity="left"
            android:text="Sync" />
    </RelativeLayout>

</RelativeLayout>
于 2013-10-31T07:08:33.337 に答える
0

これを使って

<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="50dip"
    android:background="#484848" >

    <TextView
        android:id="@+id/windowtitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Support"
        android:textSize="30sp" >
    </TextView>

    <Button
        android:id="@+id/syncbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:text="Sync" />
</RelativeLayout>

于 2013-10-31T07:09:07.417 に答える