Android的滚动型增加了额外的衬垫之上的孩子的ImageView和底部 [英] Android ScrollView adds extra padding on top and bottom of child imageview
问题描述
我有渲染滚动型的问题。从本质上讲,布局是固定的页眉和页脚,中间一个滚动视图。我们的想法是,当屏幕键盘为内容的EditText激活该图像可以如果图像的高度长于中间视图滚动。
在测试的布局,我发现,在我的Android手机(Xperia X10的Android 1.6的),还有一个填充整个堆加到ImageView的顶部和底部。
我倒是AP preciate任何建议,我怎么可以发生prevent这一点。
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<! - 标题 - >
< RelativeLayout的
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:后台=#FFFFFF>
<的TextView
机器人:文本=分享您的照片
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=左/>
<按钮
机器人:ID =@ + ID / btnStack
机器人:文本=堆栈
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真/>
< / RelativeLayout的>
< - !结束标题 - >
<! - 正文 - >
<滚动型
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:填充=5像素
机器人:后台=#CCCCCC>
< ImageView的
机器人:ID =@ + ID / IMG preVIEW
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/>
< /滚动型>
<! - 结束正文 - >
&所述;! - 页脚 - >
< RelativeLayout的
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:后台=#FFFFFF
机器人:layout_alignParentBottom =真正的>
<的EditText
机器人:ID =@ + ID /标题
机器人:文本=输入您的标题
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/>
<的LinearLayout
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID /标题
机器人:后台=#CCCCCC>
<按钮
机器人:ID =@ + ID / btnUpload
机器人:文本=分享
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1/>
<按钮
机器人:ID =@ + ID / btnCancel
机器人:文本=取消
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1/>
< / LinearLayout中>
< / RelativeLayout的>
&所述;! - 完页脚 - >
< / LinearLayout中>
我进行一些实验,添加以下语法我的Java code后,发现解决了这个问题:
IMG preview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
IMG preview.setAdjustViewBounds(真正的);
I have a problem with rendering a ScrollView. Essentially, the layout is fixed header and footer with a scrollview in the middle. The idea is that when the screen keyboard is activated for the content EditText the image can be scrolled if the height of the image is longer than the middle view.
In testing the layout, I've found that on my Android phone (Xperia X10 Android 1.6) there is a whole heap of padding added to the top and bottom of the ImageView.
I'd appreciate any suggestions as to how I can prevent this from happening.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Header -->
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF">
<TextView
android:text="Share your photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"/>
<Button
android:id="@+id/btnStack"
android:text="Stacks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<!-- End Header -->
<!-- Body -->
<ScrollView
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5px"
android:background="#CCCCCC">
<ImageView
android:id="@+id/imgPreview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</ScrollView>
<!-- End Body -->
<!-- Footer -->
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:layout_alignParentBottom="true">
<EditText
android:id="@+id/caption"
android:text="Type your caption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/caption"
android:background="#CCCCCC">
<Button
android:id="@+id/btnUpload"
android:text="Share"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/btnCancel"
android:text="Cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
<!-- End Footer -->
</LinearLayout>
I found after some experimentation that adding the following syntax to my java code solved the problem:
imgPreview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imgPreview.setAdjustViewBounds(true);
这篇关于Android的滚动型增加了额外的衬垫之上的孩子的ImageView和底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!