gpt4 book ai didi

android - 将 LinearLayout 的位置更改为屏幕的页脚

转载 作者:行者123 更新时间:2023-11-29 15:39:54 24 4
gpt4 key购买 nike

我是 android 新手,我在将红色 linearLayout 作为页脚放在屏幕上时遇到问题,这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/mainWidgetContainer"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:background = "@color/blue"
android:orientation = "vertical"
xmlns:app="http://schemas.android.com/apk/res/....." >

<RelativeLayout
android:id="@+id/topPanel"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/white">

<Button
android:id="@+id/languageButton"
android:layout_width="60dp"
android:layout_height="27dp"
android:layout_alignParentRight="true"
android:layout_marginRight="3dp"
android:layout_centerVertical= "true"
android:visibility = "gone" />
</RelativeLayout>


<!-- to add the footer here -->
<LinearLayout
android:id = "@+id/bottomPanel"
android:layout_width = "match_parent"
android:layout_height = "45dp"
android:layout_gravity="bottom"
android:gravity="bottom"
android:background="@color/red"
android:orientation="horizontal">


</LinearLayout>

</LinearLayout>

这是我得到的结果:

enter image description here

所以请任何帮助,我怎样才能在屏幕的页脚制作红色的 LinearLayout,我已经使用了 android:gravity="bottom" 而这不起作用

感谢帮助

更新:这是我在应用 Sir Lovekush Vishwakarma 解决方案时得到的结果: enter image description here

白条不见了

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/mainWidgetContainer"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:background = "@color/blue"
android:orientation = "vertical"
xmlns:app="http://schemas.android.com/apk/res/com.ofss.fcdb.mobile.android.phone.aman.launcher" >

<RelativeLayout
android:id="@+id/topPanel"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@color/white">

<Button
android:id="@+id/languageButton"
android:layout_width="60dp"
android:layout_height="27dp"
android:layout_alignParentRight="true"
android:layout_marginRight="3dp"
android:visibility="gone" />
</RelativeLayout>


<!-- to add the footer here -->
<LinearLayout
android:id="@+id/bottomPanel"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_weight="0"
android:background="@color/red"
android:gravity="bottom"
android:orientation="horizontal"></LinearLayout>

</LinearLayout>

最佳答案

像这样使用,我已经将 LinearLayout 更改为 RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/....."
android:id="@+id/mainWidgetContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
android:orientation="vertical">

<RelativeLayout
android:id="@+id/topPanel"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/white">

<Button
android:id="@+id/languageButton"
android:layout_width="60dp"
android:layout_height="27dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="3dp"
android:visibility="gone" />
</RelativeLayout>


<!-- to add the footer here -->
<LinearLayout
android:id="@+id/bottomPanel"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="bottom"
android:background="@color/red"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
</LinearLayout>

</RelativeLayout>

if you want to do it only by LinearLayout than use this below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainWidgetContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RelativeLayout
android:id="@+id/topPanel"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@color/white">

<Button
android:id="@+id/languageButton"
android:layout_width="60dp"
android:layout_height="27dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="3dp"
android:visibility="gone" />
</RelativeLayout>


<!-- to add the footer here -->
<LinearLayout
android:id="@+id/bottomPanel"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_weight="0"
android:background="@color/red"
android:gravity="bottom"
android:orientation="horizontal"></LinearLayout>

</LinearLayout>

关于android - 将 LinearLayout 的位置更改为屏幕的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42530138/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com