[英]Android Lollipop LinearLayout on the bottom of the screen
我只在Lollipop上有這個問題,舊版本工作(4.0到4.X)。
在我的xml中,我有3個部分:
問題:在Android Lollipop設備中,第三部分丟失,ListView轉到屏幕的末尾。
使用的主題:Theme.AppCompat.Light.NoActionBar(將MediaRouteButton着色為灰色)
XML代碼:
<?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-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="@dimen/cover"
android:layout_marginTop="0dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/default_cover" />
And other stuff...
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="1"
android:clipToPadding="false"
android:divider="@android:color/transparent"
android:dividerHeight="15.0sp"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:scrollbars="none" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#f0f0f0"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="5dp"
android:weightSum="10">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left">
<ImageView
android:id="@+id/imageView4"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/img1" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="10"
android:gravity="center">
<SeekBar
android:id="@+id/bar_vol"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right">
<ImageView
android:id="@+id/imageView5"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/img2" />
<android.support.v7.app.MediaRouteButton
android:id="@+id/media_route_menu_item"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="10dp"
android:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
android:background="@android:color/transparent"
android:showAsAction="always"
android:title="Cast" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
你知道問題出在哪里嗎?
在底部的LinearLayout中, android:weightSum="10"
,這是子UI元素的所有android:layout_weight
的總和。 所以...一個LinearLayout(包含SeekBar)的layout_weight="10"
重layout_weight="10"
。 這可能會影響其他UI元素並使其不可見。
另外,weightSum的父布局是水平的(android :orientation="horizontal"
),這意味着孩子應該有android :layout_width="0dp"
。 否則他們會與不可預測的結果發生沖突。 這就像你想要獲得體重計算的好處(我也喜歡它),也不要指定大小。
根據我今天的進展情況,這篇文章以及您的回復,我可能會下載您的布局xml供我進行實驗。 我計划獲得布局碩士學位,因為它很重要。
如果可以,請刪除我在上面的評論中提到的無關的LinearLayouts。 這可以讓您的生活更輕松。 否則,調試此布局可能意味着“一個全能的”。
我已經解決了我的問題! 事實上,LinearLayout落后於navigationBar。 要修復它,只需將此行添加到Activity(在setContentView();之后):
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
謝謝你的回答。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.