1

我有一个RelativeLayoutwith height 参数match_parent,在这个参数中我有另一个LinearLayoutwith property layout_alignParentBottom=true

我正在使用此布局来显示MediaController按钮。

以下是我期望的MediaController

在此处输入图像描述

但下面是我正在做的事情Lollipop 5.1(我刚刚在布局中添加了硬编码的底部边距,这根本不是任何解决方案,因为它不能在所有设备上正常工作。)

在此处输入图像描述

布局隐藏在底部后退按钮栏的后面

什么是仅根据底栏的高度从底部提供必要边距的最佳方法,因为这种布局在其他 Android 版本和早期的带有硬件后退按钮的 Android 手机中运行良好。

我的 XML 文件看起来像这样

<RelativeLayout 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"
    tools:context="com.mypack.MyActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottomLinear"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/albumArt"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:layout_gravity="center"
            android:background="@drawable/default_cover" />

        <TextView
            android:id="@+id/titleOfSong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:text="Title Of Song"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/albumOfSong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:text="Album Of Song"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/artistOfSong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:text="Artist Of Song"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/genreOfSong"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:text="Genre Of Song"
            android:textSize="18sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottomLinear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >
    </LinearLayout>

</RelativeLayout>

应用主题

<style name="AppBaseTheme" parent="Theme.AppCompat"></style>
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowDisablePreview">true</item>
    <item name="android:windowAnimationStyle">@null</item>
</style>
4

5 回答 5

0

似乎您的 Activity 以某种方式使用透明导航栏主题或类似的东西,允许在可见区域之外呈现视图。

也许提供有关您的活动的一些背景信息将有助于弄清楚到底发生了什么。

话虽如此,您应该android:fitsSystemWindows在 XML 布局的根目录中使用此属性来强制视图仅在窗口的可见区域呈现。

于 2015-06-28T13:38:05.057 回答
0

如果您想保持其他所有内容相同并仅添加底部边距,则此答案描述了一种通过减去 getRealMetrics() 和 getMetrics() 并使用差值来暗示高度尺寸来获取底部软键栏高度的方法。

自己没有测试过这种方法,但反馈似乎是积极的。

于 2015-06-28T13:51:10.190 回答
0

我通过以编程方式设置布局高度等于显示高度解决了这个问题。

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int height = size.y;
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
      statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
RelativeLayout relativeLayout =(RelativeLayout)findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)relativeLayout.getLayoutParams();
lp.height = height - statusBarHeight;
relativeLayout.setLayoutParams(lp);
于 2016-04-29T08:41:31.640 回答
0

您可以像这样在布局中使用 defaultDisplay 高度和宽度:对您来说,它是 RelativeLayout 参数。

    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    android.widget.FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) yourUI.getLayoutParams();
    params.width = metrics.widthPixels;
    params.height = metrics.heightPixels;
    params.leftMargin = 0;
    yourUI.setLayoutParams(params);
于 2015-07-20T08:04:59.603 回答
0

嗨@gprathour试试这个

<LinearLayout
        android:id="@+id/bottomLinear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="?attr/actionBarSize"
        android:orientation="horizontal" >
    </LinearLayout>

希望这可以帮助。

于 2017-06-28T10:48:05.780 回答