如何调整不同屏幕中的文本视图 (Android Studio)
How to adjust Text Views in different Screens (Android Studio)
我搜索了所有 Internet 但无法弄清楚,我的图像上有我的文本视图,当我旋转 phone 或更改为其他屏幕尺寸时,文本不会适应就像我想要的那样(左图)我已经尝试过 app:autoSizeTextType="uniform", wrap content, match parent,但这行不通。
Image
我的xml
<TextView
android:id="@+id/txt_chaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:shadowColor="#000000"
android:shadowDx="7"
android:shadowDy="6"
android:shadowRadius="1.6"
android:textSize="30sp"
android:text="Chaves"
android:textColor="#ffffff"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/gd_end_imgs1"
app:layout_constraintEnd_toStartOf="@+id/gd_foto_esq_dir"
app:layout_constraintStart_toStartOf="@+id/gd_foto_esq_esq"
app:layout_constraintTop_toTopOf="@+id/gd_start_imgs1"
app:layout_constraintVertical_bias="0.0" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/img_chaves"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:clickable="true"
android:onClick="NextChaves"
android:scaleType="fitXY"
app:layout_constraintBottom_toTopOf="@+id/gd_end_imgs1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="@+id/gd_foto_esq_dir"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/gd_foto_esq_esq"
app:layout_constraintTop_toTopOf="@+id/gd_start_imgs1"
app:layout_constraintVertical_bias="0.0"
app:shapeAppearanceOverlay="@style/RoundImage"
app:srcCompat="@drawable/chaves" />
您可以为横向模式创建新布局。
你可以通过右击res目录创建一个
New -> Android resource directory
你可以看看这个。
<androidx.drawerlayout.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
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:id="@+id/drawerlayout"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/iv_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:alpha="0.7"
android:backgroundTint="#80FFFFFF"
android:backgroundTintMode="src_over"
android:contentDescription="TODO"
android:scaleType="fitXY"
android:src="@drawable/slideshow"
app:layout_constraintBottom_toTopOf="@+id/gd_imagemP_baixo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/gd_imagemP_cima"
app:layout_constraintVertical_bias="1.0"
tools:ignore="ImageContrastCheck" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_imagemP_cima"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.055" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_imagemP_baixo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.33" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_foto_esq_esq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.15" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_foto_esq_dir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.45" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_foto_dir_esq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.55" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_foto_dir_dir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.85" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_start_imgs1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.34" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_imgs1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.48" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_start_imgs3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.50" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_imgs3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.64" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_start_imgs2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.66" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_imgs2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.80" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_start_imgs4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.82" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_imgs4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.96" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.98" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="1.0" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_texto_cima"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.35" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_texto_baixo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.35" />
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="#CDECFC"
android:fillViewport="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="MissingConstraints">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
tools:openDrawer="start"
android:orientation="horizontal">
<!--Menu layouts-->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#CDECFC"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</HorizontalScrollView>
<!--Fim do Horizontal view-->
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.35" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.65" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/img_chaves"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:clickable="true"
android:onClick="NextChaves"
app:layout_constraintBottom_toTopOf="@+id/gd_end_imgs1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="@+id/gd_foto_esq_dir"
app:layout_constraintStart_toStartOf="@+id/gd_foto_esq_esq"
app:layout_constraintTop_toTopOf="@+id/gd_start_imgs1"
app:shapeAppearanceOverlay="@style/RoundImage"
app:srcCompat="@drawable/chaves" />
<TextView
android:id="@+id/txt_chaves"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center_horizontal"
android:shadowColor="#000000"
android:shadowDx="7"
android:shadowDy="6"
android:shadowRadius="1.6"
android:text="Chaves"
android:textColor="#ffffff"
android:textStyle="bold"
app:autoSizeMaxTextSize="26sp"
app:autoSizeMinTextSize="25sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform"
app:layout_constraintBottom_toTopOf="@+id/gd_end_imgs1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="@+id/gd_foto_esq_dir"
app:layout_constraintStart_toStartOf="@+id/gd_foto_esq_esq"
app:layout_constraintTop_toTopOf="@+id/gd_start_imgs1"
app:layout_constraintVertical_bias="0.0" />
其余代码是更多图像和文本视图以及一个菜单的导航视图
我搜索了所有 Internet 但无法弄清楚,我的图像上有我的文本视图,当我旋转 phone 或更改为其他屏幕尺寸时,文本不会适应就像我想要的那样(左图)我已经尝试过 app:autoSizeTextType="uniform", wrap content, match parent,但这行不通。
Image
我的xml
<TextView
android:id="@+id/txt_chaves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:shadowColor="#000000"
android:shadowDx="7"
android:shadowDy="6"
android:shadowRadius="1.6"
android:textSize="30sp"
android:text="Chaves"
android:textColor="#ffffff"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/gd_end_imgs1"
app:layout_constraintEnd_toStartOf="@+id/gd_foto_esq_dir"
app:layout_constraintStart_toStartOf="@+id/gd_foto_esq_esq"
app:layout_constraintTop_toTopOf="@+id/gd_start_imgs1"
app:layout_constraintVertical_bias="0.0" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/img_chaves"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:clickable="true"
android:onClick="NextChaves"
android:scaleType="fitXY"
app:layout_constraintBottom_toTopOf="@+id/gd_end_imgs1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="@+id/gd_foto_esq_dir"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/gd_foto_esq_esq"
app:layout_constraintTop_toTopOf="@+id/gd_start_imgs1"
app:layout_constraintVertical_bias="0.0"
app:shapeAppearanceOverlay="@style/RoundImage"
app:srcCompat="@drawable/chaves" />
您可以为横向模式创建新布局。
你可以通过右击res目录创建一个
New -> Android resource directory
你可以看看这个
<androidx.drawerlayout.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
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:id="@+id/drawerlayout"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/iv_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:alpha="0.7"
android:backgroundTint="#80FFFFFF"
android:backgroundTintMode="src_over"
android:contentDescription="TODO"
android:scaleType="fitXY"
android:src="@drawable/slideshow"
app:layout_constraintBottom_toTopOf="@+id/gd_imagemP_baixo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/gd_imagemP_cima"
app:layout_constraintVertical_bias="1.0"
tools:ignore="ImageContrastCheck" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_imagemP_cima"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.055" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_imagemP_baixo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.33" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_foto_esq_esq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.15" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_foto_esq_dir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.45" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_foto_dir_esq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.55" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_foto_dir_dir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.85" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_start_imgs1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.34" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_imgs1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.48" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_start_imgs3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.50" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_imgs3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.64" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_start_imgs2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.66" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_imgs2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.80" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_start_imgs4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.82" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_imgs4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.96" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.98" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_end_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="1.0" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_texto_cima"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.35" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gd_texto_baixo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.35" />
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="#CDECFC"
android:fillViewport="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="MissingConstraints">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
tools:openDrawer="start"
android:orientation="horizontal">
<!--Menu layouts-->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#CDECFC"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</HorizontalScrollView>
<!--Fim do Horizontal view-->
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.35" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.65" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/img_chaves"
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:clickable="true"
android:onClick="NextChaves"
app:layout_constraintBottom_toTopOf="@+id/gd_end_imgs1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="@+id/gd_foto_esq_dir"
app:layout_constraintStart_toStartOf="@+id/gd_foto_esq_esq"
app:layout_constraintTop_toTopOf="@+id/gd_start_imgs1"
app:shapeAppearanceOverlay="@style/RoundImage"
app:srcCompat="@drawable/chaves" />
<TextView
android:id="@+id/txt_chaves"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center_horizontal"
android:shadowColor="#000000"
android:shadowDx="7"
android:shadowDy="6"
android:shadowRadius="1.6"
android:text="Chaves"
android:textColor="#ffffff"
android:textStyle="bold"
app:autoSizeMaxTextSize="26sp"
app:autoSizeMinTextSize="25sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform"
app:layout_constraintBottom_toTopOf="@+id/gd_end_imgs1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="@+id/gd_foto_esq_dir"
app:layout_constraintStart_toStartOf="@+id/gd_foto_esq_esq"
app:layout_constraintTop_toTopOf="@+id/gd_start_imgs1"
app:layout_constraintVertical_bias="0.0" />
其余代码是更多图像和文本视图以及一个菜单的导航视图