2017-12-13 15 views
0

XML 파일에 scrollView가 있습니다. 레이아웃 높이에 "match_parent"를 사용하고 싶지만 버튼이 스크롤되지 않도록 scrollview 위에 버튼을 배치하고 싶습니다. 그러나 Nexus ONE과 같은 소형 휴대 전화에서 버튼이 사라지면이 작업을 수행 할 수 없습니다. 내가 할 수있는 유일한 방법은 현재 450dp와 같은 특정 layout_Height를 사용하는 경우입니다. 하지만 450dp의 레이아웃 높이를 사용하면 Nexus ONE 크기에서 멋지게 보이지만 Nexus 6과 같은 더 큰 기기 크기에서는 너무 작습니다."모든"일반 장치 크기에 대해 XML 파일에서 scrollview를 구현하는 방법은 무엇입니까?

"일반"레이아웃의 모든 기기 크기를 만들려면 버튼에 약간의 공간 만 남겨둔 Nexus ONE처럼 스크롤보기가 있어야하나요? 여기

내가 layout_height = "450dp"로이 작업은 다음과 같습니다

enter image description here

넥서스 6 :

enter image description here

같은 XML 파일에서 두 장치 :

<Button 
    android:id="@+id/memories" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginTop="8dp" 
    android:text="Memories >" 
    app:layout_constraintBottom_toTopOf="@+id/scrollView2" 
    app:layout_constraintHorizontal_bias="0.502" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" /> 

<ScrollView 
    android:id="@+id/scrollView2" 
    android:layout_width="0dp" 
    android:layout_height="450dp" 
    android:layout_marginBottom="6dp" 
    android:layout_marginEnd="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginStart="8dp" 
    android:background="#808000" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintHorizontal_bias="0.0" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent"> 

    <LinearLayout 
     android:id="@+id/SavedBroadcasts" 
     android:layout_width="304dp" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     tools:layout_editor_absoluteX="8dp" 
     tools:layout_editor_absoluteY="0dp" > 

    </LinearLayout> 
</ScrollView> 

답변

0

XML 코드를 다음과 같이 실행하십시오. 내가 언급 한대로, 그것은 내 애플 리케이션에서 제대로 작동하고있다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools"> 

    <Button 
     android:id="@+id/memories" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="8dp" 
     android:layout_marginBottom="8dp" 
     android:text="Memories" 
     app:layout_constraintBottom_toTopOf="@+id/scrollView2" 
     app:layout_constraintHorizontal_bias="0.502" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <ScrollView 
     android:id="@+id/scrollView2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/memories" 
     android:layout_marginBottom="6dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:background="#808000" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent"> 

     <LinearLayout 
      android:id="@+id/SavedBroadcasts" 
      android:layout_width="304dp" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      tools:layout_editor_absoluteX="8dp" 
      tools:layout_editor_absoluteY="0dp"> 

     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

그리고 모든 기기에서 동일한 레이아웃을 볼 수 있습니다.

넥서스 하나 Your layout look like in Nexus One

넥서스 6 In Nexus 6

화소 (2) In Pixel 2