作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 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>
这是我得到的结果:
所以请任何帮助,我怎样才能在屏幕的页脚制作红色的 LinearLayout,我已经使用了 android:gravity="bottom"
而这不起作用
感谢帮助
更新:这是我在应用 Sir Lovekush Vishwakarma 解决方案时得到的结果:
白条不见了
这是我的代码:
<?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/
我是一名优秀的程序员,十分优秀!