Android UI布局组件在字体大小更改时错误调整大小
我有一个包含3个组件的布局,只要用户在安卓手机的显示设置中不改变字体大小,它们就可以完美地对齐。。。 出现这种情况时,UI元素无法正确对齐。我最好的猜测是,这与布局权重有关 正如你所看到的,CSR提到的内容被稍微推到下面Android UI布局组件在字体大小更改时错误调整大小,android,xml,android-layout,layout,Android,Xml,Android Layout,Layout,我有一个包含3个组件的布局,只要用户在安卓手机的显示设置中不改变字体大小,它们就可以完美地对齐。。。 出现这种情况时,UI元素无法正确对齐。我最好的猜测是,这与布局权重有关 正如你所看到的,CSR提到的内容被稍微推到下面 <LinearLayout android:id="@+id/r" android:layout_width="match_parent" android:layout_height="wrap_c
<LinearLayout
android:id="@+id/r"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/div"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:background="@color/nliveo_white"
android:padding="@dimen/pad">
<LinearLayout
android:id="@+id/rec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/recshape"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Direct Mentions"
android:textColor="#ffffff"
android:textSize="@dimen/txt_sz" />
<TextView
android:id="@+id/dir"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:gravity="center"
android:text="164"
android:textColor="#ffffff"
android:textSize="30dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/rec2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/rec2shape"
android:orientation="vertical"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Industry Mentions"
android:textColor="#ffffff"
android:textSize="@dimen/txt_sz" />
<TextView
android:id="@+id/idm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center"
android:text="30"
android:textColor="#ffffff"
android:textSize="30dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/rec3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/rec3shape"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:phoneNumber="false"
android:text="CSR Mentions"
android:textColor="#ffffff"
android:textSize="@dimen/txt_sz" />
<TextView
android:id="@+id/csr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center"
android:text="14"
android:textColor="#ffffff"
android:textSize="30sp" />
</LinearLayout>
如果文本大小在“sp”中给出,则这是一种正常行为。 查看文档中SP的定义 与比例无关的像素-这类似于dp单元,但它也是 按用户的字体大小首选项缩放。建议您使用 指定字体大小时使用此单位,因此它们将根据需要进行调整 屏幕密度和用户偏好
根据您的逻辑,您可以使用“dp”。这是由于定义文本大小时使用的单位 我猜@dimen/txt_sz定义的维度是sp,就像蓝色正方形的数字一样,正如您所看到的,这些是唯一对用户更改做出反应的维度 将文本大小更改为sp,所有内容都应固定 缩放独立像素(sp)这类似于dp单元,但它也由用户的字体大小首选项进行缩放。建议您在指定字体大小时使用此单位,以便根据屏幕密度和用户偏好进行调整
令人惊叹的!很高兴我能帮忙:)