![](/img/trans.png)
[英]Touch listener on framelayout and scrollview on inflated layout issue
[英]ScrollView inside FrameLayout layout margin's issue
我有一个非常怪异的问题,与持有ScrollView
的FrameLayout
。 我的布局如下所示:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<...
/>
</FrameLayout>
我遇到的问题是ScrollView
标记上的layout_marginTop
属性。 它在不同设备上的应用方式不同。 例如,在Nexus S(运行ICS)上,可以通过在屏幕的上添加一些空间来正确地解释它,但是在另一台(运行Gingerbread的Galaxy S2)上,它可以在屏幕的底部而不是在屏幕的顶部创建空间。
任何想法?
谢谢!
[编辑]
似乎该问题对于运行低于3.0的Android版本的所有设备都是常见的。
感谢您注意到这些无用的额外属性,它们出现在这里是因为以前FrameLayout
以前被包装在LinearLayout
。
请勿将android:layout_gravity="center_vertical"
与android:layout_width="match_parent"
。 这是没有道理的。
尝试在FrameLayout中使用android:paddingTop="50dp"
,而不是在ScrollView中使用android:layout_marginTop="50dp"
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="50dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
</LinearLayout>
</ScrollView>
尝试android:fillViewPort=true
通过使用ScrollView
上的android:paddingTop
而不是android:layout_marginTop
。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_paddingTop="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<...
/>
</FrameLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.