This implementation can always display both horizontal and vertical scrollbars
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);
}
});