TableLayout を使用しています。このレイアウトには、水平スクロールと垂直スクロールの両方が必要です。デフォルトでは、ビューで垂直スクロールを取得できますが、水平スクロールは機能しません。
Android SDK 1.5 r3 を使用しています。私はすでに試しandroid:scrollbars="horizontal"
ました。
いくつかのフォーラムで、カップケーキの更新で水平スクロールが可能であることを読みました。
レイアウトを両方向にスクロールするにはどうすればよいですか?
TableLayout を使用しています。このレイアウトには、水平スクロールと垂直スクロールの両方が必要です。デフォルトでは、ビューで垂直スクロールを取得できますが、水平スクロールは機能しません。
Android SDK 1.5 r3 を使用しています。私はすでに試しandroid:scrollbars="horizontal"
ました。
いくつかのフォーラムで、カップケーキの更新で水平スクロールが可能であることを読みました。
レイアウトを両方向にスクロールするにはどうすればよいですか?
両方のスクロール動作を実現する簡単な方法を見つけることができました。
xml は次のとおりです。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="vertical">
<HorizontalScrollView
android:layout_width="320px" android:layout_height="fill_parent">
<TableLayout
android:id="@+id/linlay" android:layout_width="320px"
android:layout_height="fill_parent" android:stretchColumns="1"
android:background="#000000"/>
</HorizontalScrollView>
</ScrollView>
手遅れですが、このコードで問題がすぐに解決されることを願っています。コードをスクロールビューの下に配置するだけです。
<HorizontalScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
//xml code
</ScrollView>
</HorizontalScrollView>
この投稿Scrollview vertical and horizontal in androidでは、可能な解決策について次のように引用しています。
Matt Clarkが Android ソースに基づいてカスタム ビューを作成しました。
そのページのクラスには、ビューの水平幅を計算するバグがあることに注意してください。Manuel Hilty による修正がコメントにあります。
解決策: 行 808 のステートメントを次のように置き換えます。
final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.leftMargin + lp.rightMargin, MeasureSpec.UNSPECIFIED);
これを使って:
android:scrollbarAlwaysDrawHorizontalTrack="true"
例:
<Gallery android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbarAlwaysDrawHorizontalTrack="true" />
この実装では、水平スクロール バーと垂直スクロール バーの両方を常に表示できます。
activity_main.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- vertical scroll view -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:fadeScrollbars="false"
android:scrollbarSize="@dimen/scroll_bar_size">
<!-- horizontal scroll view hidden scroll bar -->
<HorizontalScrollView
android:id="@+id/real_horizontal_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<!-- content view -->
<EditText
android:id="@+id/real_inside_view"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</HorizontalScrollView>
</ScrollView>
<!-- fake horizontal scroll bar -->
<HorizontalScrollView
android:id="@+id/fake_horizontal_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fadeScrollbars="false"
android:scrollbarSize="@dimen/scroll_bar_size">
<!-- fake content view that has width equals the real content view -->
<View
android:id="@+id/fake_inside_view"
android:layout_width="wrap_content"
android:layout_height="@dimen/scroll_bar_size" />
</HorizontalScrollView>
</RelativeLayout>
MainActivity.java
final EditText realInsideView = findViewById(R.id.real_inside_view);
final HorizontalScrollView realHorizontalSv = findViewById(R.id.real_horizontal_scroll_view);
final View fakeInsideView = findViewById(R.id.fake_inside_view);
final HorizontalScrollView fakeHorizontalSv = findViewById(R.id.fake_horizontal_scroll_view);
realHorizontalSv.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
fakeInsideView.setMinimumWidth(realInsideView.getWidth());
fakeHorizontalSv.setScrollX(scrollX);
}
});