【问题标题】:Scroll View doesn't show full content滚动视图不显示全部内容
【发布时间】:2013-06-16 12:39:26
【问题描述】:

我有一个 XML 文件,它有一个带有一个子 LinearLayout 的 ScrollView。在试图膨胀具有 TableLayout 和其他一些子视图的布局。但由于某种原因,tableTable 布局中的最后一个按钮不完全可见。

更新:-为了试用,我将按钮向上移动了..但最后一个 textView 也发生了同样的情况..所以我可以从中看出问题出在 ScrollView-LinearLayout 或 TableLayout。

MYScrollView.xml

          <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"
android:layout_weight="1"
android:padding="15dp"
android:fillViewport="true"
android:scrollbars="none"
tools:context=".MainActivity" >

<LinearLayout
    android:id="@+id/lo1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/border"   
    android:animateLayoutChanges="true"
    android:orientation="vertical" >

  </LinearLayout>
</ScrollView>

MyTableLayout.xml

 <?xml version="1.0" encoding="utf-8"?>
   <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LiLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left">

<com.example.tamarud.FontTextView
    android:id="@+id/textv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:gravity="center"
    android:text="La campagne Rebelle"
    android:textColor="#611711" />

<com.example.tamarud.Header2
    android:id="@+id/TextView01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="(Pour la destitution de Mohamed Mursi Al Ayat)" />

<LinearLayout
    android:id="@+id/LinearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="20dp" >

    <com.example.tamarud.Bodytext
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="• Parce que la sécurité n'a pas été retrouvée à Ce jour … On vous refuse" />

    <com.example.tamarud.Bodytext
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="• Parce que le démunis est toujours ignoré … On vous refuse" />

    <com.example.tamarud.Bodytext
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="• Parce que nous sommes encore en train de mendier des prêts de l'extérieur … On vous refuse" />
      <TableRow
        android:id="@+id/LinearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"             
        android:layout_marginTop="5dip"
        android:layout_marginBottom="5dip">

    <com.example.tamarud.Bodytext
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
        android:background="#611711"
        android:paddingBottom="10dp"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:paddingTop="10dp"
        android:text="Quartier"
        android:textColor="#FFFFFF"/>

    <Spinner
        android:id="@+id/spinner01"
            android:layout_width="0dip"
            android:layout_weight="2"
            android:layout_height="wrap_content" />
</TableRow>

<TableRow
        android:id="@+id/LinearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"             
        android:layout_marginTop="5dip"
        android:layout_marginBottom="5dip">

    <com.example.tamarud.Bodytext
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
        android:background="#611711"
        android:paddingBottom="10dp"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:paddingTop="10dp"
        android:text="E-mail"
        android:textColor="#FFFFFF" />

    <EditText
        android:id="@+id/EditText07"
            android:layout_width="0dip"
            android:layout_weight="2"
            android:layout_height="wrap_content"
        android:gravity="left"
        android:hint="Entrez E-mail"
        android:imeOptions="actionNext"
        android:textColor="#000000" />
  </TableRow>
</LinearLayout>
<Button
    android:id="@+id/submit"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp"
    android:layout_marginTop="5dp"
    android:background="#611711"
    android:paddingBottom="10dp"
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:paddingTop="10dp"
    android:text="I Accept"
    android:textColor="#FFFFFF"
    android:textSize="25sp" />

   </TableLayout>

【问题讨论】:

    标签: android scrollview android-linearlayout tablelayout


    【解决方案1】:

    唯一的解决方案是将 ScrollView 包装在 RelativeLayout 中,并同时赋予它们 WidthHeight fill_parent

    【讨论】:

      【解决方案2】:

      这是一个古老的问题,但我仍然无法回答,因为我自己也在寻找答案并找到了解决方案。您需要删除边距并用填充替换它们。

      您的原始代码:

      android:layout_marginTop="10dp"
      

      应该是什么:

      android:paddingTop="10dp"
      

      【讨论】:

        【解决方案3】:

        您也可以尝试在最后一个按钮上显式设置 dp 高度。

        android:layout_height="48dp"
        

        或者你觉得它应该是什么高度。我相信 Google 推荐 48dp 用于按钮等可点击的内容。

        您也可以尝试如下设置,从表格布局中移除底部按钮并将表格布局设置为在按钮上方对齐:

        <RelativeLayout
          android:id="@+id/scrollContainer"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
        
          <TableLayout
            android:id="@+id/myTable"
            android:layout_above="@+id/bottomButton"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/>
        
          <Button
            android:id="@+id/bottomButton"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"/>
        
        </RelativeLayout>
        

        【讨论】:

        • 感谢您的回答,但没有一个能够将整个 scrollView 包装在 RelativeLayout 而不仅仅是 TableLayout..
        【解决方案4】:

        尝试删除您的填充和边距顶部。

        【讨论】:

        • 我试过了。没啥事儿。只是为了试用,我将按钮向上移动..但效果发生在最后一个 textView..所以我可以从中得到问题是 ScrollView-LinearLayout-TableLayout
        • 你尝试移除 ScrollView、LinearLayout 和 TableLayout 上的 padding + margin 看看是不是这样?
        • 是的,我试过了..还是一样..只有当我删除任何 textViews 时它才会得到修复
        【解决方案5】:

        我总是面临这个愚蠢的问题,我正在做的是将layout_marginBottom 添加到主视图或最后一个视图等于最后一个视图的高度,甚至等于需要的剪辑区域显示,如:

        <ScrollView
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           .
           .>
        
           <RelativeLayout
               android:id="@+id/main"
               android:layout_width="match_parent"
               android:layout_height="wrap_content">
        
                 .
                 .
                 <!--some views-->
                 .
                 .
        
                 <!--last view-->
                 <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_marginBottom="60dp">
        
                 </LinearLayout>
        
           </RelativeLayout>
        
        </ScrollView>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-08-28
          • 1970-01-01
          • 1970-01-01
          • 2019-06-09
          • 1970-01-01
          相关资源
          最近更新 更多