Android ScrollView 在子图像视图的顶部和底部添加了额外的填充

Android ScrollView adds extra padding on top and bottom of child imageview(Android ScrollView 在子图像视图的顶部和底部添加了额外的填充)
本文介绍了Android ScrollView 在子图像视图的顶部和底部添加了额外的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在渲染 ScrollView 时遇到问题.本质上,布局是固定的页眉和页脚,中间有一个滚动视图.这个想法是,当为内容 EditText 激活屏幕键盘时,如果图像的高度比中间视图长,则可以滚动图像.

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.

在测试布局时,我发现在我的 Android 手机 (Xperia X10 Android 1.6) 上,ImageView 的顶部和底部添加了一大堆填充.

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>

推荐答案

经过一些实验,我发现在我的 java 代码中添加以下语法可以解决问题:

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 ScrollView 在子图像视图的顶部和底部添加了额外的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)