你好我想问一下
现在我调整了很多文字视图并正确设置样式,问题是当屏幕尺寸发生变化时,文字视图会变得太大或太小
我尝试制作不同的布局文件,但它不起作用
我使用SP,当从设备切换到另一个
时,文本仍与文本重叠我为不同的屏幕制作了超过10个布局文件,但仍无法控制它
问题是:
有没有办法逻辑地更改文本大小而不必创建替代布局或尺寸文件?
以下是我的代码
的示例 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="org.ultradroid.metaldetectorfree.welcome1"
android:orientation="vertical"
android:weightSum="1"
tools:ignore="UseCompoundDrawables">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="UselessParent">
<ImageView
android:id="@+id/imageView8"
android:layout_width="match_parent"
android:layout_height="260dp"
app:srcCompat="@drawable/metal"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/welcome"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="@color/aqua"
android:textSize="60sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/WelcomeTextDescription"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/aqua"
android:textSize="40sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatButton
android:id="@+id/next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/next"
android:textAllCaps="false"
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"
app:backgroundTint="@color/aqua" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:1)
您所做错的是,您为所有文字视图定义static text size
,使用dimens.xml
针对不同的屏幕尺寸,并指定{{1}的值如下图所示dimen
答案 1 :(得分:1)
答案 2 :(得分:0)
您可以对TextView使用自动调整大小
$image_properties = array(
'src' => 'images/picture.jpg',
'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
'class' => 'post_images',
'width' => '200',
'height'=> '200',
'title' => 'That was quite a night',
'rel' => 'lightbox'
);
img($image_properties);
// <img src="http://url/index.php/images/picture.jpg" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a night" rel="lightbox" />
这将根据您的屏幕宽度自动调整文字大小
有关详细信息,请参阅android official documentation