我的布局有问题,无法在高分辨率(如1920x1080)内拉伸。 作为根布局,我使用以下样式的约束布局:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:focusable="true"
android:focusableInTouchMode="true"
tools:context="njc.nhutrinhgold.MainActivity">
<ImageView
android:id="@+id/imgNen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:visibility="visible"
app:layout_constraintDimensionRatio="16:9"
app:srcCompat="@drawable/xxhdpibg"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp"
tools:layout_width="match_parent" />
和Manifest.xml
<supports-screens
android:anyDensity="true"
android:compatibleWidthLimitDp="960"
android:largeScreens="true"
android:largestWidthLimitDp="960"
android:normalScreens="false"
android:requiresSmallestWidthDp="960"
android:resizeable="false"
android:smallScreens="false"
android:xlargeScreens="true" />
我想将布局扩展到任何屏幕分辨率,但在高分辨率的仿真器上它看起来像这样:
其实我没弄清楚是什么问题
答案 0 :(得分:3)
这样做,并告诉我你得到了什么,因为这是这样做的理想方式,因为每个人都在说同样的事情但是这样做。 match_parent 通常是关键
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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:focusable="true"
android:focusableInTouchMode="true"
tools:context="njc.nhutrinhgold.MainActivity">
<ImageView
android:id="@+id/imgNen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centreCrop"
android:visibility="visible"
app:layout_constraintDimensionRatio="16:9"
app:srcCompat="@drawable/xxhdpibg"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="8dp"
tools:layout_width="match_parent" />
删除adjustViewBound并将scaleType设置为centreCrop,您将看到更改
**注意:** 这是为了让布局占据整个屏幕并进行调整(拉伸到整个屏幕)
答案 1 :(得分:1)
不要硬编码Constraint布局的高度和宽度以及其中的ImageView。将其设置为match_parent,它将在任何设备中全屏展开。
答案 2 :(得分:1)
试试这个:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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:focusable="true"
android:focusableInTouchMode="true"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imgNen"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:visibility="visible"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/ic_launcher"
/>
</android.support.constraint.ConstraintLayout>
答案 3 :(得分:0)
您已经给出了硬编码的宽度和高度。如果你继续处理硬编码的宽度和高度,它将永远不会拉伸。