我有一个设置活动,它扩展了 PreferenceActivity
. 然而,我也有一个自定义的偏好,我添加了使用我自己的 layout
. 问题是,我如何在自己的布局中使用相同的资源(paddingmargin)?我希望列表中的所有元素看起来都是对齐的。
你可以在resvalues目录下定义一个dimens文件。
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
</resources>
然后把这个变量用在所有你想用的地方,如果你想修改app的设计,很容易,只需要一次编辑。
<TextView
android:id="@+id/skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:margin="@dimen/activity_horizontal_margin"
android:text="@string/start_"
android:textColor="@color/white"
android:textSize="16sp"/>