132 件。在该文件中,分别定义名称为“title”、“padding”、“introduce”和“titlePadding”的尺寸资源。关键代码如下:
<resources>
<dimen name="title">26dp</dimen>
<dimen name="padding">6dp</dimen>
<dimen name="introduce">16dp</dimen>
<dimen name="titlePadding">10dp</dimen>
</resources>
然后,打开l布局文件,分别为id为title、company、url和introduce的TextView 组件设置android:textSize属性、android:padding属性或者android:paddingLeft属性,用于改变各组件的文字大小及内边距。修改后的代码如下:
<TextView
android:text="@string/title"
android:padding="@dimen/titlePadding"
android:textSize="@dimen/title"
android:textColor="@color/title"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:textColor="@color/introduce"
android:text="@string/introduce"
android:textSize="@dimen/introduce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:text="@string/company"
android:gravity="center"
android:textColor="@color/company"
android:padding="@dimen/padding"
android:layout_width="match_parent"
数组格式字符串转数组
android:layout_height="wrap_content"
/>
<TextView
android:text="@string/url"
android:gravity="center"
android:textColor="@color/url"
android:paddingLeft="@dimen/padding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
再次运行例7-1的程序,将显示如图
7-3所示的运行结果。
图7-3  使用尺寸资源设置文字大小及内边距后的运行结果

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。