1

TextViews複数を 1 つの下に配置しようとしてScrollViewいますが、これを行うとアプリがクラッシュします。同じテキストを 2 回下に配置するにはどうすればよいですか?

  <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:layout_below="@id/linear">

    <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/lorem_ipsum"/>

    <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/lorem_ipsum"/>
  </ScrollView> 
4

4 に答える 4

3

アンドロイドのドキュメントに従って:-

http://developer.android.com/reference/android/widget/ScrollView.html

ScrollView は FrameLayout です。つまり、スクロールするコンテンツ全体を含む子を 1 つ配置する必要があります。この子自体が、オブジェクトの複雑な階層を持つレイアウト マネージャーである場合があります。よく使用される子は、垂直方向の LinearLayout であり、ユーザーがスクロールできるトップレベル項目の垂直配列を提示します。

Scrollview には常に子レイアウトが 1 つだけ含まれます。また、線形レイアウトには、子レイアウトを水平または垂直に管理するための方向プロパティがあります

コードは次のようになります。

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical" >
         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lorem_ipsum"/>

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lorem_ipsum"/>
   </LinearLayout></ScrollView>

上記のコードが役立つと思います。

于 2015-05-28T09:26:02.340 に答える
1

ScrollView の直接の子は、RelativeLayout や LinearLayout など、複数の子をサポートする別のレイアウトにする必要があります。

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="20dp"
    android:layout_marginTop="20dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lorem_ipsum" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lorem_ipsum" />
    </LinearLayout>

</ScrollView>
于 2015-05-28T09:09:37.340 に答える
1

Scrollviewは子ビューを 1 つしか持つことができないため、レイアウトとテキストビューをこのレイアウト内に配置します。

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:layout_below="@id/linear">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lorem_ipsum"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lorem_ipsum"/>

    </LinearLayout> 

</ScrollView> 
于 2015-05-28T09:08:16.847 に答える
1

スクロール ビューは、子を 1 つだけ持つことができます。したがって、 ScrollView 内で LinearLayout を使用し、その中であなたがしたいことをします。このような

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="@string/app_name" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="@string/app_name" />
</LinearLayout>

于 2015-05-28T09:15:05.990 に答える