大佬教程收集整理的这篇文章主要介绍了android – 材料设计 – 操作栏标题和内容的左边距不匹配,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
由于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>@H_985_2@myactivity.xml
<RelativeLayout xmlns:android="http://scheR_53_11845@as.android.com/apk/res/android" xmlns:tools="http://scheR_53_11845@as.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:layou@R_618_11164@elow="@id/tvEditPlaylisTinfo"> </ListView> </RelativeLayout>
但不知何故,我的内容被“关闭”大约8dp(模拟器,Lollipop 22).
我正在使用父主题Theme.AppCompat.Light.DarkActionBar的自定义主题,但我只更改了颜色,所以我认为这不是我的问题的根源.
我错过了什么?
android:layout_marginLeft="@dimen/content_horizontal_margin"
您的父标记已经指定了填充应该是什么:
<RelativeLayout xmlns:android="http://scheR_53_11845@as.android.com/apk/res/android" xmlns:tools="http://scheR_53_11845@as.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">
此外,只是为了兴趣,这里是The difference between Padding and Margin.
根据与@ 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); }
为工具栏创建自定义视图
<RelativeLayout xmlns:android="http://scheR_53_11845@as.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>
这应该可以帮助您实现目标!对你很好的研究!
以上是大佬教程为你收集整理的android – 材料设计 – 操作栏标题和内容的左边距不匹配全部内容,希望文章能够帮你解决android – 材料设计 – 操作栏标题和内容的左边距不匹配所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。