2017-12-27 7 views
0

일부보기가있는 ScrollView가 있습니다. ScrollView의 내용 높이가 화면 높이보다 작 으면 마지막 뷰를 맨 아래쪽에 놓기를 원합니다. 어떻게해야합니까?내용 높이가 화면 높이보다 작 으면 ScrollView의 아래쪽에보기를 적용하십시오.

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:gravity="center_horizontal"> 

      <View ... /> 

      <View ... /> 

      <View ... /> 

      <View ... /> // this one should be on bottom if LinearLayout's contents don't exceed screen height 
     </LinearLayout> 
</ScrollView> 
+0

상대 레이아웃을 사용하고 "align_parentBottom"속성을 true로 지정 했습니까? – Umair

답변

1

당신이 linnerLayout

의 하단에 원하는 추가 다음 코드 버튼을보기 전에

 <Space 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

있는 LinearLayout의 +

변경 layout_height는 match_parent하는

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 

+

하는 android:fillViewport="true"

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 
+1

완벽하게 작동합니다. –

1

당신은 android:fillViewport="true" .below와 ScrollView의 루트의 자식으로 RelativeLayout를 사용할 수있는 ScrollView에 추가하는 예입니다.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/txt1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_height="wrap_content" 
     /> 

</RelativeLayout> 

1

이 시도 :

스크린 샷

enter image description here

XML 코드

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

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:gravity="center" 
       android:text="Some views" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:orientation="vertical"> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Click" /> 

      </LinearLayout> 

     </RelativeLayout> 

    </ScrollView> 

</LinearLayout> 
0

아래처럼 컨테이너 내부보기 귀하의 의견을 넣을 수 있습니다 : -

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/yourScrollView" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true"> 

<RelativeLayout 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="Your Button" 
     /> 

</RelativeLayout> 

이 당신을 위해 작동합니다.

관련 문제