Android:在多行textview下方放置按钮

时间:2013-02-02 13:24:57

标签: android eclipse button textview

我正在设计Android应用程序而且我被卡住了。尝试了很多事情,但到目前为止没有任何帮助。 我有一个包含多个TextView和按钮的活动。 其中一个textviews包含一个地址,但它可以是多行的。所以有时它有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

1 个答案:

答案 0 :(得分:0)

使用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- "/>
相关问题