2016-05-13 15 views
0

スクロールビュー内にあるコンテンツをスクロールしても、常にデバイスの物理的中心にあるドットを表示したい。これは私の現在のコードですが、どこに配置するのか分からないので、ドットはここではありません。スクロール位置はコードを介してのみ設定されるため、中央に配置された要素がスクロールビューをブロックする場合は問題ありません。 Scrollviewの現在のビューポートに要素を中央に配置

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:deviceIds="wear_square" 
android:gravity="center"> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/vertsv" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <HorizontalScrollView 
     android:id="@+id/horisv" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true"> 

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

      <ImageView 
       android:id="@+id/imageView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/map" /> 
     </LinearLayout> 
    </HorizontalScrollView> 
</android.support.v4.widget.NestedScrollView> 

ソリューション:

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:deviceIds="wear_square"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/vertsv" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <HorizontalScrollView 
     android:id="@+id/horisv" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true"> 

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

      <ImageView 
       android:id="@+id/imageView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/map" /> 
     </LinearLayout> 
    </HorizontalScrollView> 
</android.support.v4.widget.NestedScrollView> 
</LinearLayout> 
<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:src="@drawable/ic_my_location_black_24dp" /> 
</RelativeLayout> 
+0

xmlから混乱しているレイアウトを構築するのではなく、なぜonDraw()からこの点を描画できなかったのですか? –

+0

あなたはあなたのイメージの中央のみにしたいですか?何か説明してください。 –

+0

最も簡単な方法は、ドットをスクロールビューから外すことです。この場合、必要に応じて調整することができます。 –

答えて

1

はあなたのレイアウトで何かの下にあなたのドットを入れてください。また、LinearLayoutではなく、FrameLayout/RelativeLayoutを親の親コンテナとして使用する必要があります。

関連する問題