簡體   English   中英

如何制作2個圖像視圖,每個視圖的大小可以覆蓋水平滾動視圖內的線性布局內的屏幕

[英]How to make 2 images views each be sized to cover screen inside a linear layout inside a horizontal scrollview

我試圖在horizo​​ntalscrollview內的linearlayout內獲得2(或更多根據需要)的圖像視圖,這樣每個圖像都可以縮放以適應屏幕高度而不會扭曲圖像,即一個圖像在屏幕上顯示盡可能大,滾動查看下一個。

一旦添加了第二個圖像,我就會得到彼此相鄰的2個小圖像(兩個圖像的尺寸都是217 * 300px)。 目前我的activity_main.xml如下所示..

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
        >

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            >
            <ImageView
                android:id="@+id/image1"
                android:src="@drawable/luke"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitCenter"
                />
            <ImageView
                android:id="@+id/image2"
                android:src="@drawable/luke"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitCenter"
                />


        </LinearLayout>
    </HorizontalScrollView>


</FrameLayout>

我已經嘗試了布局上的match_parent,fill_parent,wrap_content的各種組合,圖像視圖上的所有scaleTypes,並花了一天時間瀏覽網絡尋找類似於我想要的示例,但沒有運氣。

我會說這兩件事:

     <ImageView
          android:layout_height = "match_parent"
          android:layout_width = "10dp" />

這是棘手的部分。 在運行時獲取屏幕寬度,並將其設置為imageView。

我傾向於使用帶有自定義頁面適配器的viewpager來顯示您的縮放imageview,而不是嘗試以您當前的方式執行此操作。

視圖尋呼機/適配器將為您處理視圖重新打印,頁面捕捉等。

如何使用

android:width="0"
android:weight ="1"
android:height="match_parent"

在imageViews中

和match_parent否則布局中的位置。

暫無
暫無

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

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