我有许多具有不同ViewGroup根的布局(LinearLayouts,RelativeLayouts等).这些视图都按预期工作,但现在我正在尝试添加顶部导航栏.问题是根可以有不同的填充,如果我只是在每个布局中包含我的布局,导航栏的宽度受父代填充的限制.我希望这个导航栏忽略根的左/右/顶部填充,并在布局的最顶部完全全宽.我可以在导航栏的布局中做些什么来实现这一点,或者我注定要修改所有现有布局以适应这种情况?
Ric*_*Yao 34
虽然这看起来是一个非常糟糕的主意,但您可以通过将父ViewGroup的clipToPadding属性设置为false然后在子视图上设置负边距来完成您要查找的内容.
例:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="#EEE"
android:clipToPadding="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
android:background="#333"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginTop="-10dp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
上面的示例有效,但我建议您只需将顶部导航栏放在这些ViewGroup之外,其中包含您要避免的填充.
| 归档时间: |
|
| 查看次数: |
15294 次 |
| 最近记录: |