【问题标题】:Scroll view doesn't show bottom part滚动视图不显示底部
【发布时间】:2013-02-19 14:51:54
【问题描述】:

我有一个包含滚动视图的相对布局。但是当滚动视图中有更多文本时,它不会显示底部文本,它位于我的按钮后面。我该如何解决这个问题?

这是我所做的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00AEEC"
    android:orientation="vertical"
    android:weightSum="100" >

    <RelativeLayout
        android:id="@+id/details_header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="clip_horizontal"
        android:background="#00AEEC"
        android:padding="20dp" >



        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/onlywithalcohol_heading_page2" />

    </RelativeLayout>

 <RelativeLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_below="@+id/details_header"
     android:layout_centerHorizontal="true"
     android:layout_margin="20dp" >

     <TextView
         android:id="@+id/details_country"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentTop="true"
         android:layout_centerHorizontal="true"
         android:layout_marginBottom="20dp"
         android:text="USA"
         android:textAlignment="center"
         android:textAppearance="?android:attr/textAppearanceMedium" />

     <TextView
         android:id="@+id/details_title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@id/details_country"
         android:layout_centerHorizontal="true"
         android:layout_marginBottom="20dp"
         android:gravity="center_horizontal"
         android:text="Fastest Time To Drink A Pint Of Soda Water, Consume A Bowl Of Macaroni And Cheese With Chopsticks, Eat And Read A Fortune Cookie And Take A Shot Of Peach Schnapps "
         android:textAlignment="center"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="#FFFF00" />

     <ScrollView
         android:layout_width="fill_parent"
         android:layout_height="200dp"
         android:layout_alignParentBottom="true"
         android:layout_below="@id/details_title"
         android:layout_centerHorizontal="true" >

         <TextView
             android:id="@+id/details_description"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginBottom="20dp"
             android:gravity="center_horizontal"
             android:paddingLeft="10dp"
             android:paddingRight="10dp"
             android:text="Sam Birdsong removed a cork from an empty bottle of wine using just a napkin in two minutes, 55.47 seconds.He stipulated beforehand that he had to begin with an unopened bottle, uncork it and pour out the wine, then shove the cork back inside the bottle and pull it out with a cloth napkin"
             android:textAlignment="center"
             android:textAppearance="?android:attr/textAppearanceMedium" />
     </ScrollView>
 </RelativeLayout>

 <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_centerHorizontal="true"
     android:layout_margin="10dp"
     android:background="#00AEEC"
     android:orientation="vertical" >

     <Button
         android:id="@+id/details_back_btn"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center"
         android:padding="10dp"
         android:text="@string/back_btn"
         android:textSize="18sp"
         android:textStyle="bold" />
 </LinearLayout>

</RelativeLayout>

【问题讨论】:

  • 你必须使用 RelativeLayout 吗?为什么不使用 LinearLayout 它应该适合你
  • @Saksak 现在我使用线性布局,但我的按钮不在屏幕上...
  • 在下面查看我的答案

标签: android xml android-relativelayout android-scrollview


【解决方案1】:

给包含Button的LinearLayout添加一个id,例如:

android:id="@+id/bottomLayout"

在包含scrollView的RelativeLayout中使用这个:

android:layout_above="@+id/bottomLayout"

请注意,底部边距为 20dp,如果您不想要它,可以使用 android:layout_marginLeft、android:layout_marginRight 和 android:layout_marginTop 来确保您在其他任何地方都有 20dp 边距。

【讨论】:

    【解决方案2】:

    将您的布局更改为 LinearLayout,它应该适合您,您可能需要使用

    android:gravity="bottom"
    

    对齐屏幕底部的按钮

    你可能需要使用

    android:layout_weight=""
    

    如果需要。

    这是一个可以垂直放置在LinearLayout 中的块:

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ic_launcher" />
    
    <TextView
        android:id="@+id/details_country"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="20dp"
        android:text="USA"
        android:textAlignment="center"
        android:textAppearance="?android:attr/textAppearanceMedium" />
    
    <TextView
        android:id="@+id/details_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/details_country"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="20dp"
        android:gravity="center_horizontal"
        android:text="Fastest Time To Drink A Pint Of Soda Water, Consume A Bowl Of Macaroni And Cheese With Chopsticks, Eat And Read A Fortune Cookie And Take A Shot Of Peach Schnapps "
        android:textAlignment="center"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#FFFF00" />
    
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="200dp"
        android:layout_alignParentBottom="true"
        android:layout_below="@id/details_title"
        android:layout_centerHorizontal="true" >
    
        <TextView
            android:id="@+id/details_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:gravity="center_horizontal"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Sam Birdsong removed a cork from an empty bottle of wine using just a napkin in two minutes, 55.47 seconds.He stipulated beforehand that he had to begin with an unopened bottle, uncork it and pour out the wine, then shove the cork back inside the bottle and pull it out with a cloth napkin , and this wilk take for ever and ever out the wine, then shove the cork back inside the bottle and pull it out with a cloth napkin , and this wilk take for ever and ever out the wine, then shove the cork back inside the bottle and pull it out with a cloth napkin , and this wilk take for ever and ever out the wine, then shove the cork back inside the bottle and pull it out with a cloth napkin , and this wilk take for ever and ever "
            android:textAlignment="center"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </ScrollView>
    
    <Button
        android:id="@+id/details_back_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight=""
        android:gravity="bottom"
        android:padding="10dp"
        android:text="back"
        android:textSize="18sp"
        android:textStyle="bold" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      • 2017-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2013-06-16
      相关资源
      最近更新 更多