Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按钮对齐在真实设备android上不起作用_Android_Xml - Fatal编程技术网

按钮对齐在真实设备android上不起作用

按钮对齐在真实设备android上不起作用,android,xml,Android,Xml,有没有人能帮我找出我的代码出了什么问题?它的预览和预期的一样。但当我在真实设备上测试它们时,问题就出现了。我在底部添加了Admob横幅广告。在添加它之前,它是完全正常的。但现在它没有正确对齐。我的错误是什么?我应该怎么做 我的XML代码是: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_h

有没有人能帮我找出我的代码出了什么问题?它的预览和预期的一样。但当我在真实设备上测试它们时,问题就出现了。我在底部添加了Admob横幅广告。在添加它之前,它是完全正常的。但现在它没有正确对齐。我的错误是什么?我应该怎么做

我的XML代码是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:background="#FFFFFF"
android:orientation="vertical">

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView8"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/ll1"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="16dp" >

        <TextView
            android:id="@+id/textLink"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/description_product"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/result_field_product"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_centerInParent="false"
            android:layout_marginTop="20dp"
            android:gravity="center_vertical|center_horizontal"
            android:text="Example application"
            android:textSize="16sp"
            android:textIsSelectable="true" />

    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/ll1"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_above="@+id/adView"
    android:orientation="horizontal"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true">
    <Button
        android:id="@+id/btnProceed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/button_fullwidth"
        android:padding="5dp"
        android:text="@string/choose_action"
        android:textColor="@android:color/white" />
    <view
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/btnCancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/button_fullwidth"
        android:padding="5dp"
        android:text="@string/abort_action"
        android:textColor="@android:color/white" />
</LinearLayout>
<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:background="@color/colorAccent"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_home_footer">
</com.google.android.gms.ads.AdView>
这里我的一个按钮对齐了,但另一个没有对齐。我如何修复它

当前状态:

1.在线性布局中设置内容android:gravity=center\u垂直

2.确保视图已消失或不可见。然后更改为“视图”

3.如果您希望两个按钮的布局为一半,则应在按钮中设置android:layout_weight=1和android:layout_width=0dp

编辑

将根标记更改为LinearLayout

试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/res-auto"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#FFFFFF"
              android:orientation="vertical">

    <ScrollView
        android:id="@+id/scrollView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/ll1"
        android:layout_weight="1"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="16dp">

            <TextView
                android:id="@+id/textLink"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/description_product"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textSize="15sp"/>

            <TextView
                android:id="@+id/result_field_product"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_alignWithParentIfMissing="true"
                android:layout_centerInParent="false"
                android:layout_marginTop="20dp"
                android:gravity="center_vertical|center_horizontal"
                android:text="Example application"
                android:textIsSelectable="true"
                android:textSize="16sp"/>

        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/ll1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btnProceed"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/button_fullwidth"
            android:padding="5dp"
            android:text="@string/choose_action"
            android:textColor="@android:color/white"/>

        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:visibility="invisible"/>

        <Button
            android:id="@+id/btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/button_fullwidth"
            android:padding="5dp"
            android:text="@string/abort_action"
            android:textColor="@android:color/white"/>
    </LinearLayout>

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="@color/colorAccent"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_home_footer">
    </com.google.android.gms.ads.AdView>
</LinearLayout>
无论何时使用布局重量,都应根据方向将布局宽度或布局高度设置为0dp

例如,当你有android:orientation=horizontal时,使用android:layout\u width=0dp


当你有android:orientation=verticaluse android:layout\u height=0dp

你想用什么按钮对齐?我只想把BTNProced和btnCancel放在同一行。你能展示你现在看到的图片吗?@KeLiuyue请看我更新的问题。你能检查我的答案吗?谢谢。我编辑了很长时间。@Tanvir Durlove