2016-12-26 7 views
1

私は以下の活動をしています。ScrollViewが機能していないときに、以下のAndroidアクティビティをスクロール可能にするにはどうすればよいですか?

RelativeLayout全体をScrollViewでカプセル化しようとしました。しかし、それはうまくいかず、最後の2枚の画像しか表示されませんでした。そこで、私はそれを削除し、RelativeLayoutを投稿しました。助けてください。私は2つのダミー・ビューを持っていて、画面の中央に仮想の垂直線と水平線をマークし、すべての画像をそれらの線に対して整列させます。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/content_front" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/colorWhite" 
     android:fillViewport="true" 
     android:gravity="center_vertical" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context=".FrontActivity" 
     tools:showIn="@layout/activity_front" 
     > 

     <View 
      android:id="@+id/dummy" 
      android:layout_width="1dp" 
      android:layout_height="match_parent" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" /> 

     <View 
      android:id="@+id/dummy2" 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" /> 

     <ImageView 
      android:id="@+id/all1" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_above="@+id/part2" 
      android:layout_margin="20dp" 
      android:layout_toLeftOf="@+id/dummy" 
      android:layout_toStartOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/all" /> 

     <ImageView 
      android:id="@+id/part1" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_above="@+id/part3" 
      android:layout_margin="20dp" 
      android:layout_toEndOf="@+id/dummy" 
      android:layout_toRightOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part1" /> 

     <ImageView 
      android:id="@+id/part2" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_above="@+id/dummy2" 
      android:layout_marginBottom="0dp" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="20dp" 
      android:layout_toLeftOf="@+id/dummy" 
      android:layout_toStartOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part2" /> 

     <ImageView 
      android:id="@+id/part3" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_above="@+id/dummy2" 
      android:layout_marginBottom="0dp" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="20dp" 
      android:layout_toEndOf="@+id/dummy" 
      android:layout_toRightOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part3" /> 

     <ImageView 
      android:id="@+id/part4" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_below="@+id/dummy2" 
      android:layout_marginEnd="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="40dp" 
      android:layout_toLeftOf="@+id/dummy" 
      android:layout_toStartOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part4" /> 

     <ImageView 
      android:id="@+id/part5" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_below="@+id/dummy2" 
      android:layout_marginLeft="20dp" 
      android:layout_marginStart="20dp" 
      android:layout_marginTop="40dp" 
      android:layout_toEndOf="@+id/dummy" 
      android:layout_toRightOf="@+id/dummy" 
      android:adjustViewBounds="false" 
      android:contentDescription="@string/app_name" 
      android:scaleType="fitCenter" 
      android:src="@mipmap/part5" /> 
    </RelativeLayout> 

これをより効率的にする方法に関するヒントもありがとうと思います。

答えて

0

最初のヒント:レイアウトに空白以外のダミービューが必要な場合は、Spaceビューを使用してください。

第2の先端if you're supporting API 17 and above、(ちょうど、あなたのminSdkに応じて)StartEnd修飾子のサポート、ないLeftRightが含まれます。


を使用すると、偽のアンカービューを使用せずに TableLayoutGridLayoutのいずれかを用いて達成することができるやっていること、言いました。 RelativeLayoutを使用することもできます。[0,0]、[1,0]から[0,1]の位置を[0,0]、[1,1]で[1,0 ]、[0,1]などとなります。

あなたは完全にあなたの要件を指定していなかったので、私は(私も容疑者それが安価になり、将来的に異なる構成/ニーズに適応するために、コードのシンプルさと柔軟性のGridLayoutを使用する自由を取りますよ他のビューとの相対的な位置を調整するよりも、自分で確認する必要があります)。とにかくminSdkを17に設定していると思われるので、ここではLeftRightの修飾語は含まれません。

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingStart="@dimen/activity_horizontal_margin" 
    android:paddingEnd="@dimen/activity_horizontal_margin" 
    android:columnCount="2" 
    android:layout_gravity="center_horizontal"> 
    <!-- Set columnCount according to your needs. --> 

    <ImageView 
     android:id="@+id/image_1" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:adjustViewBounds="false" 
     android:layout_margin="20dp" 
     android:contentDescription="@string/app_name" 
     android:scaleType="fitCenter" 
     android:src="@mipmap/icon_1" /> 

    <ImageView 
     android:id="@+id/image_2" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:adjustViewBounds="false" 
     android:layout_margin="20dp" 
     android:contentDescription="@string/app_name" 
     android:scaleType="fitCenter" 
     android:src="@mipmap/icon_2" /> 

<!-- Rinse and repeat. --> 

</GridLayout> 
関連する問題