0

私はアンドロイド用のアプリケーションを作成していますが、奇妙な種類の問題に直面しています。問題は、ファイルの GRAPHICAL LAYOUT で同じように表示される画面の中央にボタンを配置したことですが、エミュレーターでアプリケーションを実行すると、ボタンが右側に配置され、中央に配置されません。 . 誰でも問題を指摘できますか。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:panel="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCC"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <org.miscwidgets.widget.Panel
        android:id="@+id/mytopPanel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="4dip"
        panel:animationDuration="1000"
        panel:closedHandle="@drawable/top_switcher_collapsed_background"
        panel:content="@+id/mypanelContent"
        panel:handle="@+id/mypanelHandle"
        panel:linearFlying="true"
        panel:openedHandle="@drawable/top_switcher_expanded_background"
        panel:position="top" >

        <Button
            android:id="@+id/mypanelHandle"
            android:layout_width="fill_parent"
            android:layout_height="33dip"
            android:paddingRight="50dp" />

        <LinearLayout
            android:id="@+id/mypanelContent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/editTextUserName"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:layout_marginTop="6dp"
                android:hint="@string/editUserName" >
            </EditText>

            <EditText
                android:id="@+id/editTextPassword"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:hint="@string/editUserPwd" >
            </EditText>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#323299"
                android:gravity="center"
                android:padding="4dip"
                android:text="@string/drpDwnTxt"
                android:textColor="#eee"
                android:textSize="16dip"
                android:textStyle="bold" />
        </LinearLayout>
    </org.miscwidgets.widget.Panel>

    <EditText
        android:id="@+id/editTextNumber"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:layout_marginTop="6dp"
        android:hint="@string/editNumber" >
    </EditText>

    <EditText
        android:id="@+id/editTextMessage"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_margin="3dp"
        android:hint="@string/editPwd" >
    </EditText>

    <Spinner
        android:id="@+id/spinnerGateway"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:entries="@array/spinnerList"
        android:prompt="@string/spinnerPrompt" />

    <Button
        android:id="@+id/btnSend"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:onClick="save"
        android:text="@string/StrbtnSend" >
    </Button>
</LinearLayout>

</FrameLayout>

ここに画像の説明を入力

4

3 に答える 3

0

この新しいレイアウト ファイルは私の仕事をしてくれました。たった 1 つの小さなエラーが問題を引き起こしていました。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:panel="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCC"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <org.miscwidgets.widget.Panel
        android:id="@+id/mytopPanel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        panel:animationDuration="1000"
        panel:closedHandle="@drawable/top_switcher_collapsed_background"
        panel:content="@+id/mypanelContent"
        panel:handle="@+id/mypanelHandle"
        panel:linearFlying="true"
        panel:openedHandle="@drawable/top_switcher_expanded_background"
        panel:position="top" >

        <Button
            android:id="@+id/mypanelHandle"
            android:layout_width="wrap_content"
            android:layout_height="33dip"
            android:layout_gravity="center_horizontal" />

        <LinearLayout
            android:id="@+id/mypanelContent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/editTextUserName"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:layout_marginTop="6dp"
                android:hint="@string/editUserName" >
            </EditText>

            <EditText
                android:id="@+id/editTextPassword"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:hint="@string/editUserPwd" >
            </EditText>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#323299"
                android:gravity="center"
                android:padding="4dip"
                android:text="@string/drpDwnTxt"
                android:textColor="#eee"
                android:textSize="16dip"
                android:textStyle="bold" />
        </LinearLayout>
    </org.miscwidgets.widget.Panel>

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

        <AutoCompleteTextView
            android:id="@+id/mmWhoNo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="10dp"
            android:layout_toLeftOf="@+id/btnContact"
            android:hint="To: Type to search"
            android:textSize="13sp" />

        <Button
            android:id="@+id/btnContact"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_alignParentRight="true"
            android:layout_marginTop="10dp"
            android:background="@drawable/contacts_icon"
            android:textSize="18dp" >
        </Button>
    </RelativeLayout>

    <EditText
        android:id="@+id/editTextMessage"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_margin="3dp"
        android:hint="@string/editPwd" >
    </EditText>

    <Spinner
        android:id="@+id/spinnerGateway"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:entries="@array/spinnerList"
        android:prompt="@string/spinnerPrompt" />

    <Button
        android:id="@+id/btnSend"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:text="@string/StrbtnSend" >
    </Button>

    <TextView
        android:id="@+id/txtAuthor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Designed By - Tapan Desai" />
</LinearLayout>

</FrameLayout>
于 2012-09-19T07:07:35.000 に答える
0

このコードで変更してみてください

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:panel="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCC"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <org.miscwidgets.widget.Panel
        android:id="@+id/mytopPanel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="4dip"
        panel:animationDuration="1000"
        panel:closedHandle="@drawable/top_switcher_collapsed_background"
        panel:content="@+id/mypanelContent"
        panel:handle="@+id/mypanelHandle"
        panel:linearFlying="true"
        panel:openedHandle="@drawable/top_switcher_expanded_background"
        panel:position="top" >

        <Button
            android:id="@+id/mypanelHandle"
            android:layout_width="fill_parent"
            android:layout_height="33dip"
            android:gravity="center" />

        <LinearLayout
            android:id="@+id/mypanelContent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/editTextUserName"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:layout_marginTop="6dp"
                android:hint="@string/editUserName" >
            </EditText>

            <EditText
                android:id="@+id/editTextPassword"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:hint="@string/editUserPwd" >
            </EditText>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#323299"
                android:gravity="center"
                android:padding="4dip"
                android:text="@string/drpDwnTxt"
                android:textColor="#eee"
                android:textSize="16dip"
                android:textStyle="bold" />
        </LinearLayout>
    </org.miscwidgets.widget.Panel>

    <EditText
        android:id="@+id/editTextNumber"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:layout_marginTop="6dp"
        android:hint="@string/editNumber" >
    </EditText>

    <EditText
        android:id="@+id/editTextMessage"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_margin="3dp"
        android:hint="@string/editPwd" >
    </EditText>

    <Spinner
        android:id="@+id/spinnerGateway"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:entries="@array/spinnerList"
        android:prompt="@string/spinnerPrompt" />

    <Button
        android:id="@+id/btnSend"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:onClick="save"
        android:text="@string/StrbtnSend" >
    </Button>
</LinearLayout>

</FrameLayout>
于 2012-09-18T08:57:49.257 に答える
-1

ボタン xml からパディングを削除し、重力を中央に設定します

layout_gravity="center"//can also set horizontal or vertical

アクセスしているJavaクラスにマージンやパディングを設定していないことを確認してください。

于 2012-09-18T09:35:12.520 に答える