0X0*_*gar 7 android android-layout material-design
我正在尝试按照布局指南- 指标和线条设置屏幕边距.具体而言,移动屏幕上的列表内容应具有72 dp的边距,并与指南中所示的标题一致:
由于Android Studio会自动在res/dimens.xml中生成边距值,我认为我会通过添加自己的"内部"边距来使我的内容与标题保持一致:
dimens.xml
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<!-- 16 + 56 = 72 = "Content left margin from screen edge" -->
<dimen name="content_horizontal_margin">56dp</dimen>
</resources>
Run Code Online (Sandbox Code Playgroud)
myactivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<TextView
android:id="@+id/tvEditPlaylistInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/content_horizontal_margin"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="test" />
<ImageButton
android:layout_width="36dp"
android:layout_height="36dp"
android:src="@drawable/action_current"
android:layout_alignBottom="@id/tvEditPlaylistInfo"
android:layout_toRightOf="@id/tvEditPlaylistInfo"
android:layout_marginLeft="16dp"/>
<ListView
android:id="@+id/lvAudioFiles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_horizontal_margin"
android:layout_below="@id/tvEditPlaylistInfo">
</ListView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但不知何故,我的内容被"关闭"大约8dp(模拟器,Lollipop 22).
我正在使用父母的自定义主题,Theme.AppCompat.Light.DarkActionBar但我只改变颜色,所以我认为这不是我的问题的根源.
我错过了什么?
从您的TextView和ListView:删除此
android:layout_marginLeft="@dimen/content_horizontal_margin"
Run Code Online (Sandbox Code Playgroud)
您的父标记已经指定了填充应该是什么:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
Run Code Online (Sandbox Code Playgroud)
它关闭的原因是因为你填充,然后设置边距.
另外,只是为了兴趣,这里是Padding和Margin之间的区别.
UPDATE
根据与@ 0X0nosugar的讨论,我们已经达到以下代码有助于实现目标的程度:
要更改ActionBar,应将以下内容添加到onCreate():
ActionBar actionBar = getSupportActionBar();
if (actionBar != null)
{
View customView = getLayoutInflater().inflate(R.layout.custom_action_bar, null);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(customView);
}
Run Code Online (Sandbox Code Playgroud)
为工具栏创建自定义视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/accent_deeporangeA400"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MyMusicApp"
android:id="@+id/ab_title"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这应该可以帮助您实现目标!对你很好的研究!