gpt4 book ai didi

android - 如何动态调整约束布局中的 TextView 大小以适应不同的屏幕尺寸?

转载 作者:行者123 更新时间:2023-11-29 23:48:01 25 4
gpt4 key购买 nike

截图

1) Samsung J6

2) Lenovo Vibe X3 6 inch screen

问题是我如何调整歌词的 textview 以在 J6 型号中有更多屏幕可用时增加高度,而在屏幕空间较小时降低高度?或者有什么方法可以避免 J6 模型中播放/暂停控制按钮下方看起来很奇怪的空间吗?当我增加 textview 和按钮之间的空间时,J6 变得正确并且在 lenovo 型号中按钮离开屏幕??

我的 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:background="@drawable/bg"
android:theme="@style/Base.Theme.AppCompat.Light.DarkActionBar"
tools:context=".MainActivity">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="660dp">

<ImageView
android:id="@+id/imageView"
android:layout_width="239dp"
android:layout_height="240dp"
android:layout_marginEnd="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginStart="25dp"
android:layout_marginTop="25dp"
android:adjustViewBounds="false"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/albumcover"
tools:ignore="ContentDescription" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="34dp"
android:layout_height="32dp"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp"
android:layout_marginTop="32dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView"
app:srcCompat="@drawable/ic_baseline_surround_sound_24px" />

<ImageView
android:id="@+id/imageView3"
android:layout_width="34dp"
android:layout_height="32dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView"
app:srcCompat="@drawable/ic_baseline_more_vert_24px" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:text="Human Nature"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />

<SeekBar
android:id="@+id/seekBar2"
android:layout_width="402dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:progressTint="@color/colorAccent"
android:thumbTint="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />

<ImageView
android:id="@+id/imageView5"
android:layout_width="43dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/seekBar2"
app:srcCompat="@drawable/ic_baseline_pause_24px" />

<ImageView
android:id="@+id/imageView6"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toEndOf="@+id/imageView5"
app:layout_constraintTop_toTopOf="@+id/imageView5"
app:srcCompat="@drawable/ic_baseline_skip_next_24px" />

<ImageView
android:id="@+id/imageView7"
android:layout_width="30dp"
android:layout_height="26dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toStartOf="@+id/imageView5"
app:layout_constraintTop_toTopOf="@+id/imageView5"
app:srcCompat="@drawable/ic_baseline_skip_previous_24px" />

<ImageView
android:id="@+id/imageView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="36dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="36dp"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toStartOf="@+id/imageView7"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView7"
app:srcCompat="@drawable/ic_baseline_shuffle_24px" />

<ImageView
android:id="@+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="36dp"
android:layout_marginRight="8dp"
android:layout_marginStart="36dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView6"
app:layout_constraintTop_toTopOf="@+id/imageView6"
app:srcCompat="@drawable/ic_baseline_repeat_24px" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:text="Housee De Racket"
android:textAlignment="center"
android:textColor="#ffffff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="79dp"
android:layout_marginTop="24dp"
android:text="this space is for lyrics "
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp"
android:layout_marginTop="8dp"
android:text="01:23"
android:textColor="#ffffff"
app:layout_constraintBottom_toTopOf="@+id/seekBar2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2"
app:layout_constraintVertical_bias="1.0" />

<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="8dp"
android:text="01:24"
android:textColor="#ffffff"
app:layout_constraintBottom_toTopOf="@+id/seekBar2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView3"
app:layout_constraintVertical_bias="1.0" />


</android.support.constraint.ConstraintLayout>

</LinearLayout>

最佳答案

检查这篇关于 Autosizing TextViews 的文章

在确定 TextView 如何调整大小方面实际上有很大的灵 active 。文档中的示例之一:

<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="2sp" />

关于android - 如何动态调整约束布局中的 TextView 大小以适应不同的屏幕尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51168092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com