Development Tip

레이아웃을 가로 및 세로로 스크롤하려면 어떻게해야합니까?

yourdevel 2020. 12. 3. 20:42
반응형

레이아웃을 가로 및 세로로 스크롤하려면 어떻게해야합니까?


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 xmlns:android="http://schemas.android.com/apk/res/android"
            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>

이 게시물 에서 Android의 Scrollview vertical 및 horizontal에서는 가능한 솔루션에 대해 다음과 같이 설명합니다.

Matt Clark은 Android 소스를 기반으로 사용자 정의보기를 작성했으며 완벽하게 작동하는 것 같습니다. http://blog.gorges.us/2010/06/android-two-dimensional-scrollview

해당 페이지의 클래스에는 뷰의 수평 너비를 계산하는 버그가 있습니다. 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" />

참고 URL : https://stackoverflow.com/questions/1399605/how-can-i-make-my-layout-scroll-both-horizontally-and-vertically

반응형