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


88

화면을 아래로 스크롤하여 "Replied By :"섹션의 데이터를 볼 수 없습니다. 레이아웃을 스크롤 가능하게 만들려면 어떻게해야합니까?

대체 텍스트

답변:


200

모든 것을 다음과 같이 감싸십시오 ScrollView.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <!-- Here you put the rest of your current view-->
</ScrollView>

David Hedlund가 말했듯이, ScrollView 하나의 항목 만 포함 할 수 있습니다. 따라서 다음과 같은 것이 있다면 :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <!-- bla bla bla-->
</LinearLayout>

다음으로 변경해야합니다.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
        <!-- bla bla bla-->
    </LinearLayout>
</ScrollView>

15
+1. 빠른 참고 :이 ScrollView당신이 현재 가지고하는 의견이 많은 경우에만, 한 아이를 포함 할 수 있습니다 그래서, 당신은 하나 개의보기 그룹에서 그들을 포장 할 필요가 (발언권 LinearLayout)
데이비드 Hedlund는

1
당신에게 @ 데이비드 Hedlund는 감사
Prateek 라즈

내 문제하시기 바랍니다 도움을 해결하는 방법을 나 stackoverflow.com/questions/38588702/...
카디

40

상대 레이아웃과 함께 스크롤보기를 사용하는 경우 :

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"> <!--IMPORTANT otherwise backgrnd img. will not fill the whole screen -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:background="@drawable/background_image"
    >

    <!-- Bla Bla Bla i.e. Your Textviews/Buttons etc. -->
    </RelativeLayout>
</ScrollView>

1
뷰포트 태그 란 무엇인가
Ruchir Baronia

4

모든 것을 ScrollView 안에 감싸십시오.

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ruatech.sanikamal.justjava.MainActivity">
<!-- Here you put the rest of your current view-->
</ScrollView>

0

위에 적힌대로 했는데도 스크롤이 안 나오면 .....

을 설정 android:layout_height="250dp"하거나 말할 수 xdp어디에 x어떤 수치 값이 될 수 있습니다.


0

예, 매우 간단합니다. 이 안에 코드를 넣으십시오.

<androidx.core.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" 
    android:layout_height="match_parent">

//YOUR CODE

</androidx.core.widget.NestedScrollView>
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.