Прокрутка Android View / Форма больше, чем размер экрана - PullRequest
2 голосов
/ 28 августа 2011

У меня есть вид / форма / активность, когда отображаются в альбомной / горизонтальной режиме, становятся больше, чем размер экрана.Мне было интересно, как пользователь может прокручивать представление вниз?

В настоящее время все мои виджеты находятся в линейном макете как стипендиаты.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:isScrollContainer="true">

<Widget1></Widget1>
<Widget2></Widget2>
<Widget3></Widget3>
<Widget4></Widget4>
<Widget5></Widget5>
</LinearLayout> 

Ответы [ 3 ]

6 голосов
/ 28 августа 2011

Если я правильно понимаю ваш вопрос: у вас может быть ScrollView вне вашего LinearLayout, и у вас есть HorizontalScrollView внутри вашего LinearLayout, куда вы можете добавить свои виджеты.Это позволит вам прокручивать как влево-вправо, так и сверху вниз.

Пример кода:

<ScrollView android:id="@+id/scrollView1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/linearLayout1"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="vertical">
    <HorizontalScrollView android:id="@+id/horizontalScrollView1"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
        <LinearLayout android:id="@+id/linearLayout2"
            android:layout_width="match_parent" android:layout_height="match_parent"
            android:orientation="horizontal">
            <Widget1/>
            <Widget2/>
        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout>
</ScrollView>  
3 голосов
/ 28 августа 2011

Во-первых, спасибо @Dimitris Makris, который помог мне найти правильное направление и написал для меня код. Но правильное решение, которое я нашел для себя, заключается в следующем.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/scrollView1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<Widget1/>
<Widget2/>

</LinearLayout>
</ScrollView>
0 голосов
/ 20 июня 2012

Что помогло в моей ситуации, так это поставить ScrollView как самый внешний вид, затем HorizontalScrollView, а затем вложил все внутри.

* ПРИМЕЧАНИЕ. - ScrollView не поддерживает горизонтальную прокрутку, следовательно, вложенный HorizontalScrollView.

<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/scroller"    
  android:layout_width="fill_parent"    
  android:layout_height="fill_parent"
  android:fillViewport="true">
  <HorizontalScrollView
    android:id="@+id/horizontalScrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
      ...
    </LinearLayout>
  </HorizontalScrollView>
</ScrollView>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...