【问题标题】:Android: placing button below multiline textviewAndroid:在多行文本视图下方放置按钮
【发布时间】:2013-02-02 13:24:56
【问题描述】:

我正在设计一个 Android 应用程序,但我遇到了困难。尝试了很多东西,但到目前为止没有任何帮助。 我有一个包含多个 TextView 和按钮的活动。 其中一个文本视图包含一个地址,但它可以是多行的。所以有时它有 1 行,有时最多 4 行。 现在我想在下面放置一个按钮。当 textview 只有 1 行时,没问题,但是当它有更多时,文本会越过我的按钮。 这是我的 XML 文件中的视图:

<TextView
   android:id="@+id/locatie"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceMedium"/>
<Button
   android:id="@+id/button1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentLeft="true"
   android:layout_alignParentRight="true"
   android:layout_below="@+id/locatie"
   android:text="@string/mapknop" />

我在我的 textview 上尝试了很多东西,比如最小行和最大行,但没有任何效果。有人有解决方案吗? 谢谢

编辑: 这是我完整的 XML 文件

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/evenement"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:contentDescription="@string/affiche"
        android:onClick="showImage" />

    <TextView
        android:id="@+id/datum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView1"
        android:layout_marginTop="19dp"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/uren"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/datum"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/DETAILS"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/uren"
        android:layout_marginTop="24dp"
        android:text="@string/details"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/DETAILS"
        android:text="@string/vvk"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:text="@string/kassa"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:text="@string/locatie"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/vvk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView2"
        android:layout_marginLeft="18dp"
        android:layout_toRightOf="@+id/textView3"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/kassa"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView3"
        android:layout_alignLeft="@+id/vvk"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <!--  PROBLEM OCCURS FROM HERE -->
    <TextView
        android:id="@+id/locatie"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/kassa"
        android:textAppearance="?android:attr/textAppearanceMedium"/>

      <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/locatie"
        android:text="@string/mapknop" />

      <!--  UNTIL HERE -->

    <TextView
        android:id="@+id/omschrijving"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView4" />

    <TextView
        android:id="@+id/TextView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/omschrijving"
        android:layout_marginTop="49dp"
        android:layout_alignLeft="@+id/lineup"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold" 
        android:text="@string/lineup"/>

    <TextView
        android:id="@+id/lineup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/TextView5" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button1"
        android:text="@string/omschrijving"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold" />



</RelativeLayout>

编辑:这里是 1 行与 2 行的屏幕截图

http://i.imgur.com/uChHNmA.jpg?1 http://i.imgur.com/5w0mjoh.jpg

【问题讨论】:

  • 请发布您的整个 xml 文件
  • 你的xml没有问题,发布完整的布局xml。
  • 我想,至少xml有问题,你可以看看这行,android:layout_alignParentLeft="true" android:layout_alignParentRight="true"
  • 编辑了我的帖子,查看出现问题的cmets,谢谢

标签: android eclipse button textview


【解决方案1】:

使用 Edittext 代替 TextView 会更好。 这是对我有用的代码示例,希望对您有用。

<EditText
    android:id="@+id/locatie"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginRight="5dp"
    android:hint="locatie"
    android:textColor="#000000"
    android:lines="1"
    android:maxLength="32"
    android:digits="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKJLZXCVBNM0123456789- "/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    • 2014-06-22
    • 1970-01-01
    相关资源
    最近更新 更多