Android 带重量和最小高度的布局
我正在开发一个带有简单用户界面(y顺序)的广播应用程序:Android 带重量和最小高度的布局,android,xml,android-layout,android-constraintlayout,Android,Xml,Android Layout,Android Constraintlayout,我正在开发一个带有简单用户界面(y顺序)的广播应用程序: 掩护 头衔+艺术家 按钮播放/暂停/ 声带 但我面临屏幕尺寸的问题 盖子需要保持在顶部,并保持1:1的比例(如果有房间)。 声音条保持在底部 带有曲目信息和播放/暂停按钮的部件需要调整自身大小,以占用剩余空间并将其中的内容居中 我通过对中间布局使用权重为1的LinearLayout来实现这一点,但在小屏幕上,内容会被裁剪 我尝试了多种解决方案(协调器、相对等),但没有一个能像预期的那样工作 当我的内容没有被裁剪时,它将对齐底部而不是中
- 掩护
- 头衔+艺术家
- 按钮播放/暂停/
- 声带
<LinearLayout
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include
android:id="@+id/layout_cover"
layout="@layout/layout_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="1dp" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<include
android:id="@+id/layout_informations"
layout="@layout/layout_informations"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/medium_margin"
android:elevation="2dp" />
<include
android:id="@+id/layout_actionbar"
layout="@layout/layout_actionbar"
android:layout_width="match_parent"
android:layout_height="@dimen/layout_actionbar_height"
android:layout_margin="@dimen/common_margin" />
</LinearLayout>
<include
android:id="@+id/layout_soundbar"
layout="@layout/layout_soundbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
提前感谢您的帮助
Fab像这样试试
选项1
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="@drawable/ic_audiotrack_black_24dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:gravity="center"
android:background="@color/colorPrimary">
<!--Title play pause-->
<FrameLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/colorPrimaryDark">
<!--Soundbar-->
</LinearLayout>
</LinearLayout>
在这种情况下,
ImageView
将始终保持1:1的比例,如果没有足够的空间,则会变小。请发布输出的屏幕截图如果没有足够的空间(最初为1:1),则封面(绿色条纹)需要自行裁剪。信息/按钮部分(绿色括号)需要将其自身居中于盖和声条之间的剩余空间中。
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:src="@drawable/ic_audiotrack_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintDimensionRatio="w,1:1"
app:layout_constraintHorizontal_bias="0.538"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:gravity="center"
android:background="@color/colorPrimary">
<!--Title play pause-->
<FrameLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/colorPrimaryDark">
<!--Soundbar-->
</LinearLayout>
</LinearLayout>