簡體   English   中英

Android:ImageView縮放到ScrollView中的屏幕寬度

[英]Android: ImageView scale to screen width within a ScrollView

我是android編程的新手,偶然發現了一個layout問題。

首先,我有一個Linearlayout ,帶有textview ,2個buttons和一個可縮放以適合屏幕的imageview

現在,我想將其放置在scrollview ,以便可以將imageview縮放到更大的比例(縮放到屏幕的寬度)。

沒有scrollview一切都很好,但是有了scrollview ,我的imageview不再縮放了。

我做錯什么? 我在StackOverflow上嘗試了許多解決方案,但無法使其與ScrollView一起使用。 提前致謝!

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/pageno" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/texta" />

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/textb" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:src="@drawable/page1" />

</LinearLayout>
</ScrollView>

使LinearLayout / RelativeLayout成為父視圖。 在其中進行滾動視圖並設置alignparentTop = true。 該scrollView將包含一個布局,所有其他視圖都將放置在該布局中。

暫無
暫無

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

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