簡體   English   中英

horizo​​ntalscrollview設置子元素以填充horizo​​ntalscrollview寬度

[英]horizontalscrollview set child elements to fill horizontalscrollview width

基本上我有一個水平滾動視圖,通過監視onTouch事件我正在分頁(即:滾動視圖(頁面)的每個可見部分“點擊”到滾動時的下一個,而不是只有一個標准的ScrollView 。 iOS中的scrollviews)。

現在我想找到一種方法讓內部子項繼承與scrollview相同的寬度(設置為"fill_parent" )。

這是我的XML幫助:

<HorizontalScrollView
        android:id="@+id/scrollview"
        android:layout_height="0dp" 
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/scrollviewbg">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent">

            <ImageView
                android:src="@drawable/content1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <ImageView
                android:src="@drawable/content2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <ImageView
                android:src="@drawable/content3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </HorizontalScrollView>

如您所見,scrollview設置為width fill_parent ,其中有一個LinearLayout 現在,目前有三個圖像的設置寬度和高度與屏幕的寬度相似,但我想要做的是更改3個LinearLayout的圖像。

每個LinearLayout需要繼承與滾動視圖相同的寬度,以便在應用我的代碼時每個都占用一個完整的“頁面”,就像它一樣。

我該怎么做? 這是我需要使用代碼做的事情嗎? 我需要什么代碼?

謝謝。

我知道它不是直接的答案,但更容易從兼容包中ViewPager用戶提供分頁功能。 您可以在samples文件夾中找到一個示例(有關源代碼,請參閱src/com/example/android/supportv4/app/FragmentPagerSupport.java )。

試試這個: android:fillViewport =“true”

<HorizontalScrollView

    android:fillViewport="true"

    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<TextView
    android:layout_gravity="right"
    android:background="@drawable/black_border"
    android:id="@+id/displayText"
    android:layout_width="match_parent"
    android:scrollHorizontally="true"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:padding="20dp"
    android:text=""
    android:textSize="20sp" />
</HorizontalScrollView>

在水平滾動視圖內,我有一個文本視圖,你可以嘗試圖像視圖

將所有layout_height參數設置為fill_parent 你應該全屏看到圖像。

暫無
暫無

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

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