Textview响应边距/填充

时间:2016-04-18 18:55:24

标签: android android-layout textview

好像我的Android设计出了问题。这是问题所在:

Here is the image

正如你所看到的那样," http:// LABEL 2 GOES HERE"正好在标签1文本的顶部:"这只是对标签1的测试......."我怎样才能让它成为" http:// LABEL 2走到这里"将始终低于"标签1" 30dp无论多长或多短?

我怎样才能这样做

这是我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:tools="http://schemas.android.com/tools"
  android:layout_height="match_parent"
  android:layout_width="match_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"

    <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:minHeight="1000dp">

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="About:"
        android:id="@+id/about"
        android:textSize="16dp"
        android:layout_marginTop="30dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/label1"
        android:textSize="16dp"/>

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Website:"
        android:id="@+id/website"
        android:textSize="16dp"
        android:layout_marginTop="30dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/label2"
        android:textSize="16dp"
        android:autoLink="web"/>

  </RelativeLayout>
</ScrollView>

3 个答案:

答案 0 :(得分:0)

确保你有一个相对布局作为根元素,并使用标签2上最后一个标签的android:layout_below id。并在标签2上添加android:layout_marginTop,你应该好好去。

http://developer.android.com/guide/topics/ui/layout/relative.html http://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html

答案 1 :(得分:0)

您希望将所有内容放在实际描述之下。以下是我所做的应该适合你的事情。

enter image description here

增加尺寸

enter image description here

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:id="@+id/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="About:"/>


    <TextView
        android:id="@+id/aboutDescription"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/about"
        android:text="Description \n description"/>

    <TextView
        android:id="@+id/website"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Website:"
        android:layout_below="@id/aboutDescription"
        />

    <TextView
        android:id="@+id/websiteDescription"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/website"
        android:layout_below="@id/aboutDescription"
        android:text="Description \n description"/>

</RelativeLayout>

答案 2 :(得分:0)

以下是您要找的内容

在父级中采用线性布局,为不同的行采用2种不同的相对布局(不必要)

相对布局具有高度换行内容,因此会根据您的数据大小增加减少量。

enter image description here

这是代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="About :"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="16dp" />

    <TextView
        android:id="@+id/label1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/about"
        android:text="This is just a test for lebel 1 \nThis is just a test for lebel 1 \nThis is just a test for lebel 1 \nThis is just a test for lebel 1"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="16dp" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/website"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Website :"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="16dp" />

    <TextView
        android:id="@+id/label2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/website"
        android:minLines="4"
        android:text="This is just a test for lebel 2 \nThis is just a test for lebel 2 \nThis is just a test for lebel 2 \nThis is just a test for lebel 2 \nThis is just a test for lebel 2"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="16dp" />
</RelativeLayout></LinearLayout>