如何在布局文件中将按钮按下到屏幕底部?

时间:2019-04-03 15:55:20

标签: android layout

我的Android应用程序中具有以下layout.xml。我想将按钮移到屏幕底部。就在我的广告之上。但它将保持在列表视图的正下方。我该如何实现?我尝试过layout_gravity =“ bottom | right”,也尝试过layout_alignParentBottom =“ true”都没有将按钮放在我想要的位置。任何帮助表示赞赏

    <?xml version="1.0" encoding="utf-8"?>
<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"
    android:id="@+id/linearLayout_main"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity">

    <!--custome toolbar-->
    <include layout="@layout/tool_bar" />

    <!--Wifi name and state-->
    <LinearLayout
        android:id="@+id/linear_wifi_name"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/wifi_icon_id"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.15"
            android:src="@drawable/ic_wifi_white_36dp"/>

        <TextView
            android:id="@+id/wifi_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.50"
            android:textSize="18sp"
            android:gravity="left"
            android:layout_gravity="center"
            android:text="SOHOWIFI" />

    </LinearLayout>

    <!--Progess bar-->
    <ProgressBar
        style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="visible"
        android:id="@+id/progress_bar" />


    <TextView
        android:id="@+id/result_local"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:typeface="monospace"
        android:text="Local Network:"
        android:paddingLeft="5dp"
        android:textColor="@color/colorAccent"
        android:textSize="18sp"/>

    <!-- output of list local ip and public ip-->

    <ListView
        android:id="@+id/local_network"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/round_button"
        android:text="scan"
        android:id="@+id/scan_button"
        android:layout_gravity="bottom|right"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="10dp"
        android:textSize="12dp" />


    <!-- banner ads for AdsMob-->
    <RelativeLayout android:layout_width="fill_parent"
        android:id="@+id/ad_layout"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:layout_alignParentBottom="true"
        android:layout_alignBottom="@+id/home_layout">
        <com.google.android.gms.ads.AdView
            android:id="@+id/adView_main"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="@string/app_banner_ad">
        </com.google.android.gms.ads.AdView>
    </RelativeLayout>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

您按钮的父级布局为/** * @param DomainObjectInterface $object * @param $targetLanguageUid * @return DomainObjectInterface|null */ public function translate($object, $targetLanguageUid) { /** @var AbstractDomainObject $objectCopy */ $objectCopy = new $this->objectType; $properties = ObjectAccess::getGettableProperties($object); foreach ($properties as $propertyName => $propertyValue) { ObjectAccess::setProperty($objectCopy, $propertyName, $propertyValue); } $objectCopy->_setProperty('_localizedUid', $object->getUid()); $objectCopy->_setProperty('_languageUid', $targetLanguageUid); $objectCopy->_setProperty('_versionedUid', $object->getUid()); return $objectCopy; }

LinearLayout适用于layout_gravity="bottom|right"

FrameLayout适用于layout_alignParentBottom="true"

但是您必须使用适当的布局更改父布局。