簡體   English   中英

如何獲得imageView水平和垂直滾動?

[英]How can I get my imageView to scroll horizontally as well as vertically?

我有一個包含文本的圖像,並且在較大的屏幕設備上可以正常顯示,但是在較小的屏幕上無法讀取文本。 我決定使用一種尺寸並在較小的屏幕上滾動。 我使用下面的代碼設置了垂直滾動和水平滾動,但是只能垂直滾動。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical">
    <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="820px"
        android:layout_height="fill_parent">
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            tools:context=".CategoriesActivity">
.
.
.
            <ImageView
                android:id="@+id/termsImg"
                android:layout_width="450dp"
                android:layout_height="600dp"
                android:layout_below="@+id/headerPanel"
                android:background="@drawable/screen1" />
    </HorizontalScrollView>
</ScrollView>

水平滾動在較大的屏幕上有效,但在240或320尺寸的屏幕上無效。

我需要更改什么以允許imageView水平和垂直滾動?

就是這樣

<ScrollView
    android:id="@+id/layout0"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/layout1"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <HorizontalScrollView
            android:id="@+id/layout2"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:id="@+id/layout3"
                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageView
                    <!-- Your ImageVIew -->
                </ImageVIew>
            </LinearLayout>

        </HorizontalScrollView>

    </LinearLayout>

</ScrollView>

但是如您所見,它似乎效率很低。 您可以通過將圖像視圖縮放到適當的scaleType並使用一個ScrollView來解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM