2017-11-25 2 views
0

상단에 몇 가지 안드로이드 위젯을 추가하고 그 다음에 Scrollview와 그 위의 몇 가지 위젯을 추가하고 싶습니다. Scrollview가 완전히 채워지면 위젯 (Scrollview 이후에 있어야 함)에 할당 된 공간을 차지하기 시작합니다. 궁극적으로 위젯이 부적절하게 나타납니다.스크롤 뷰 아래에 위젯 추가

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    tools:layout_editor_absoluteX="8dp" 
    tools:layout_editor_absoluteY="8dp" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:weightSum="10"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Enter Data" 
     android:gravity="center_horizontal"/> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Submit" 
     android:layout_weight="1"/> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="6"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:background="@android:color/holo_green_light"> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_green_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_blue_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_green_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_blue_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_green_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_blue_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_green_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_blue_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_green_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_blue_light"/> 
      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="new Button" 
       android:background="@android:color/holo_green_light"/> 
     </LinearLayout> 
    </ScrollView> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Enter Data Again" 
     android:gravity="center_horizontal"/> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Submit Again" 
     android:layout_weight="1"/> 

</LinearLayout> 

In the following picture it can be seen that the Scollview uses the space allocated for widgets below it.

답변

0
아래처럼 레이아웃 코드를 변경

:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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" 
    android:orientation="vertical" 
    tools:layout_editor_absoluteX="8dp" 
    tools:layout_editor_absoluteY="8dp"> 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:gravity="center_horizontal" 
     android:text="Enter Data" /> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text1" 
     android:text="Submit" /> 

    <ScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/text2" 
     android:layout_below="@+id/button"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/holo_green_light" 
      android:orientation="vertical"> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_green_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_blue_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_green_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_blue_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_green_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_blue_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_green_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_blue_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_green_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_blue_light" 
       android:text="new Button" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@android:color/holo_green_light" 
       android:text="new Button" /> 
     </LinearLayout> 
    </ScrollView> 

    <TextView 
     android:id="@+id/text2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/button2" 
     android:gravity="center_horizontal" 
     android:text="Enter Data Again" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="Submit Again" /> 

</RelativeLayout> 

보기처럼 될 것입니다 :

enter image description here

+0

고마워요, 선생님! 그것은 효과가 있었다. –

+0

@MuradKhateebAbbasi이 대답이 도움이 되었다면,이 답변을 upvote하고 수락하십시오. 도움을 청합니다. –