Android ScrollView добавляет дополнительные отступы сверху и снизу дочернего изображения. - PullRequest
16 голосов
/ 21 ноября 2010

У меня проблема с рендерингом 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>

Ответы [ 4 ]

33 голосов
/ 23 ноября 2010

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

    imgPreview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    imgPreview.setAdjustViewBounds(true);
21 голосов
/ 21 апреля 2011

Просто добавьте следующий атрибут в описание XML для ImageView, сделайте свою работу:

android:adjustViewBounds="true"
10 голосов
/ 22 ноября 2010
android:fillViewport="true"
android:fadingEdge="none"

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

1 голос
/ 14 февраля 2016

вы можете установить 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>
...