010*_*101 5 android android-layout
所以我有这个简单的主要布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/top_bar" />
<android.support.v4.view.ViewPager
android:id="@+id/VpPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后我使用FragmentPagerAdapter用不同的片段填充ViewPager,除了一件事以外,它按预期工作.
假设其中一个片段具有此布局,其中window是一个包含带圆角的简单形状的XML文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:orientation="vertical"
android:background="@drawable/window">
...
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后,由于某种原因,16dp的余量被完全忽略.但是,如果我将布局设置为:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:orientation="vertical"
android:background="@drawable/window">
...
</LinearLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
然后它工作.我真的不想将整个布局嵌套在另一个布局中,只是为了使边距有效.另外,由于背景原因,我不能使用填充.知道第一个版本的问题是什么吗?任何替代方案,我不必将布局放在另一个?
| 归档时间: |
|
| 查看次数: |
1839 次 |
| 最近记录: |