Android ScrollView добавляет дополнительные дополнения в верхней и нижней части детского изображения - программирование

Android ScrollView добавляет дополнительные дополнения в верхней и нижней части детского изображения

У меня проблема с отображением ScrollView. По существу, макет - это фиксированный верхний и нижний колонтитулы с прокруткой в ​​середине. Идея заключается в том, что при активации экранной клавиатуры для содержимого EditText изображение можно прокручивать, если высота изображения длиннее среднего.

При тестировании макета я обнаружил, что на моем Android-телефоне (Xperia X10 Android 1.6) в верхней и нижней части ImageView добавлена ​​целая куча дополнений.

Я был бы признателен за любые предложения относительно того, как я могу предотвратить это.

<?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>
4b9b3361

Ответ 1

После некоторых экспериментов я обнаружил, что добавление следующего синтаксиса к моему java-коду решает проблему:

    imgPreview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    imgPreview.setAdjustViewBounds(true);

Ответ 2

Просто добавив следующий атрибут в описание вашего ImageView XML, выполните следующее задание:

android:adjustViewBounds="true"

Ответ 3

android:fillViewport="true"
android:fadingEdge="none"

Используйте эти свойства в прокрутке.

Ответ 4

вы можете установить marginTop и bottom для отрицательного числа для этого типа ребенка

<HorizontalScrollView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#ffffff"
        android:overScrollMode="never"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_marginBottom="-10dp"
            android:layout_marginTop="-10dp">


    </LinearLayout>

</HorizontalScrollView>