Meh*_*glu 21 scrollview android-layout
我有一个简单的布局如下:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D23456" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#FFFFFF" >
<ImageView
android:layout_width="match_parent"
android:layout_height="800dp"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
scrollview的背景是粉红色,线性布局里面有android图标图像,高度为800dp(不适合屏幕).我期待看到的是,imageview浮动在粉红色的背景中,每边(顶部,底部,左侧,右侧)的边距为10dp.但是当我滚动到底部时,滚动视图不会滚动到保证金,所以滚动的底部是imageview而不是粉红色的边距.
我怎么能阻止这个?这使用户认为页面尚未结束并使他想要滚动更多.
Meh*_*glu 51
我后来发现,在@olefevre 的以下主题/sf/answers/1181992101/中已经回答了类似的情况.
使用填充添加包围当前LinearLayout的额外LinearLayout并删除内部LinearLayout的布局边距解决了以下问题:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#D23456"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
<ImageView
android:layout_width="match_parent"
android:layout_height="800dp"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
Fil*_*ito 18
由@Mehmet Katircioglu发布的解决方案运行良好,但你可以解决问题只需将android:layout_margin更改为android:padding,没有额外的视图.像这样:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#D23456"
android:padding="10dp" >
<!-- Your content (ImageView, buttons...) -->
<LinearLayout/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19179 次 |
| 最近记录: |