【问题标题】:Remove space for horizontal scroll bar删除水平滚动条的空间
【发布时间】:2014-09-25 06:33:39
【问题描述】:

我在表格布局中动态添加表格行。当我同时使用垂直和水平滚动条时。由于水平滚动,我在布局中获得了一些空间。我的 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:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:scrollbars="none">

         <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:scrollbars="none">

<TableLayout 
        android:stretchColumns="*"
        android:id="@+id/main_table" 
        android:layout_weight="1" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent">


</TableLayout>
        </HorizontalScrollView>
    </ScrollView>







</LinearLayout>

截图是-

我想从右侧删除那个空间。

【问题讨论】:

  • 你试过android:layout_weight="wrap_content"为你的TableLayout
  • Anushka,我认为你必须设置 layout_width="match_parent"
  • 请发布您的布局行 xml 文件
  • @SagarPilkhwal,@pratik-我试过了,但它不起作用。它仍在右侧占用空间。
  • @DigveshPatel-我不是通过 xml 文件动态添加表行。

标签: android horizontal-scrolling


【解决方案1】:

简单的改变

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:scrollbars="none">

     <HorizontalScrollView
    android:id="@+id/horizontalScrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:scrollbars="none">

到这里

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:scrollbars="none">

     <HorizontalScrollView
    android:id="@+id/horizontalScrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:scrollbars="none">

【讨论】:

  • (因此将 wrap_content 更改为 match_parent 的宽度)
  • @Kostya Khuta- 它不工作。仍然占据右侧的空间。
  • 这是你的整个 xml 文件吗?
  • @KostyaKhuta-我有其他 xml 用于设置 viewpager。它与此无关。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-16
  • 2013-03-25
  • 2011-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
相关资源
最近更新 更多