【问题标题】:Android button refuses to reduce its size in a table?Android按钮拒绝在表格中减小其大小?
【发布时间】:2014-07-14 06:58:30
【问题描述】:

我有一个位于表格中的按钮,但该按钮会在屏幕上拉伸,从而拉伸我的图像,使其变得丑陋。我尝试过 wrap_content、fill_parent 和 match_parent,但它们都给出了相同的结果。这是我的xml。为什么按钮不减小它的大小???

              <?xml version="1.0" encoding="utf-8"?>
              <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@drawable/bg2"
                    android:orientation="vertical" >


                   <TableRow>
                     <ImageView
                             android:contentDescription="@string/contents"
                             android:id="@+id/imageView1"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_gravity="center_horizontal|top"
                             android:paddingTop="10dp"
    android:src="@drawable/lesson1" />
  </TableRow>

  <TableRow>

      <TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/alpha"
          android:paddingLeft="15dp"
          android:textAppearance="?android:attr/textAppearanceLarge" />

  </TableRow>


  <TableRow>
        <TextView
          android:id="@+id/textView3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:paddingLeft="15dp"
          android:textStyle="italic"
          android:text="@string/alphanote"
          android:textAppearance="?android:attr/textAppearanceMedium" />

  </TableRow>


  <TableRow>
      <TextView
          android:id="@+id/textView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/directions2"
          android:paddingLeft="15dp"
          android:textAppearance="?android:attr/textAppearanceMedium" />

  </TableRow>

  <TableRow>

      <Button
          android:id="@+id/Button1"
          android:layout_width="14dp"
          android:background="@drawable/playstart" />

  </TableRow>

  <TableRow>
      <TextView
          android:id="@+id/textView4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/alpha1"
          />

      </TableRow>
        </TableLayout>     
     </ScrollView>

【问题讨论】:

    标签: android xml button


    【解决方案1】:

    如果您只有一列,我不知道您为什么要打扰 TableLayoutTableRowTableLayout 用于多列表。

    话虽如此,您无法通过您提到的任何方法控制TableLayout 中的列宽。而是在TableLayout 本身上使用android:stretchColumnsandroid:shrinkColumns

    我不确定这是否会起作用,因为TableLayout 背后的要点是尽量将行填充到表格的宽度。您可能应该将其转换为简单的垂直LinearLayout

    【讨论】:

    • 我需要使用滚动视图并将我的按钮并排放置。
    • @user3623689:您没有并排的任何按钮。要在TableLayout 中有多个列,一个或多个TableRow 元素需要有多个子元素。您的所有TableRow 元素都有一个子元素,因此您只有一列。另外,您只有一个按钮。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-16
    • 2012-09-12
    • 2018-12-30
    • 2019-11-07
    • 1970-01-01
    • 2012-03-02
    • 2016-11-16
    相关资源
    最近更新 更多