ScrollViewの連動について
解決済
回答 1
投稿
- 評価
- クリップ 0
- VIEW 2,651
前提・実現したいこと
123
456
789
3×3の表があるとして、1はスクロールしない。2,3は横スクロールのみ。4,7は縦スクロールのみ。5,6,8,9は縦横スクロールし、2,3の横スクロールと5,6,8,9,の横スクロール、4,7の縦スクロールと5,6,8,9の縦スクロールを連動させたいです。
発生している問題・エラーメッセージ
xmlでScrollView,HorizontalScrollViewを使い実現したいようにうまく囲むことができないのですが、Javaコードの方で実装する必要があるのでしょうか?またその場合どのような方法で実装することができるのでしょうか?
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
checkベストアンサー
0
・レイアウトはRelativeLayoutを使用するとできると思いますよ。
・ScrollViewとHorizontalScrollViewを継承する。
・onScrollChangedをオーバーライドする。
・スクロール量をコールバックするインターフェースを定義する。
・各ScrollViewからのスクロール量のコールバックを元に5689をスクロールする。
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.13%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
2017/01/18 19:37
2017/01/18 19:40
2017/01/18 20:20
ScrollView、HorizontalScrollViewの中身を一つの子要素にして
同じScrollViewの中に4,5,6,7,8,9をいれ、HorizontalScrollViewの中に2,3,5,6,8,9を入れる方法が思いつかないのですが、、、
2017/01/18 20:54
・2,3をHorizontalScrollViewを継承したクラスの子要素にする。
・4,7をScrollViewを継承したクラスの子要素にする。
・5,6,8,9はFrameLayoutの子要素にする。
2017/01/18 23:11 編集
下記のようなレイアウトを書いてみたのですがどうでしょうか?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</LinearLayout>
</HorizontalScrollView>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
2017/01/19 00:00
2017/01/20 11:08
2017/01/20 12:01
また、現状のレイアウトでとりあえず表示はできていますか?
方針としては
・ScrollViewを継承したクラスを作成する。
・継承したクラスでスクロール変化をコールバックできるようにする。
・取得したスクロール量をFrameLayout#scrollByに渡してFrameLayoutをスクロールする。
全部を一度に教えると混乱するだけです。順番に教えるのでまずはレイアウトから作りましょう。
2017/01/20 12:24
RelativeLayoutを使えばxmlのレイアウトのみでできるということだと思い、レイアウトだけでどうにか実装できる方法があるのかと思ってしまいました。
xmlのみでなくjavaファイルの方もいじっていく必要があるということですね。
とりあえず現状のレイアウトで5,6,8,9がスクロールしない以外は表示などは問題なくできています。
2017/01/20 12:53
次は私が回答に書いた2〜3を実装してください。
2017/01/21 23:52