Android Scroll sorgt für zusätzliche Polsterung an Ober- und Unterseite des Kindes Imageview
-
26-09-2019 - |
Frage
habe ich ein Problem mit einem Scrollview-Rendering. Im Wesentlichen wird das Layout Kopf- und Fußzeilen mit einem Scrollview in der Mitte fixiert. Die Idee ist, dass, wenn die Bildschirmtastatur für den Inhalt EditText das Bild aktiviert wird gescrollt werden kann, wenn die Höhe des Bildes länger als die mittlere Sicht ist.
Bei der Prüfung des Layouts habe ich festgestellt, dass auf meinem Android-Handy (Xperia X10 Android 1.6) gibt es einen ganzen Haufen Polsterung an den Ober- und Unterseite des Image hinzugefügt ist.
ich irgendwelche Vorschläge zu schätzen wissen würde, wie ich das verhindern kann.
<?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>
Lösung
fand ich nach einigen Experimenten, dass das Hinzufügen der folgenden Syntax zu meinem Java-Code, um das Problem zu lösen:
imgPreview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imgPreview.setAdjustViewBounds(true);
Andere Tipps
Nur das Hinzufügen des folgende Attribut zu Ihrem Image XML-Beschreibung der Arbeit machen:
android:adjustViewBounds="true"
android:fillViewport="true"
android:fadingEdge="none"
Verwenden Sie diese Eigenschaften im Scroll.
Sie können MarginTop und unten auf eine negative Zahl für das Kind wie dieses
gesetzt<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>