2015-04-06 15 views
0

我试图将我的TextView项目放置在彼此之间的距离相同,但距离不均匀。我用“android:layout_marginTop”来管理它,但没有成功。xml布局:组件之间的距离不是

我很感激任何帮助。

enter image description here

<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" 
 
    tools:context="com.bustracker.MainActivity" > 
 

 
    <TextView 
 
     android:id="@+id/textView1" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignParentTop="true" 
 
     android:layout_marginTop="5dp" 
 
     android:text="Latitude:" /> 
 

 
    <TextView 
 
     android:id="@+id/textLat" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignLeft="@+id/textView1" 
 
     android:layout_below="@+id/textView1" 
 
     android:layout_marginTop="10dp" 
 
     android:text="Large Text" 
 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 
 

 
    <TextView 
 
     android:id="@+id/textView3" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignLeft="@+id/textLat" 
 
     android:layout_below="@+id/textLat" 
 
     android:layout_marginTop="15dp" 
 
     android:text="Longitude:" /> 
 

 
    <TextView 
 
     android:id="@+id/textLong" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignLeft="@+id/textView3" 
 
     android:layout_below="@+id/textView3" 
 
     android:layout_marginTop="20dp" 
 
     android:text="Large Text" 
 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 
 

 
    <TextView 
 
     android:id="@+id/textView5" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignLeft="@+id/textLong" 
 
     android:layout_below="@+id/textLong" 
 
     android:layout_marginTop="25dp" 
 
     android:text="Bus available wifi:" /> 
 

 
    <TextView 
 
     android:id="@+id/textWifi" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignLeft="@+id/textLong" 
 
     android:layout_below="@+id/textView5" 
 
     android:layout_marginTop="30dp" 
 
     android:text="Large Text" 
 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 
 

 
    <TextView 
 
     android:id="@+id/textView2" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignLeft="@+id/textWifi" 
 
     android:layout_below="@+id/textWifi" 
 
     android:layout_marginTop="35dp" 
 
     android:text="Time stamp:" /> 
 

 
    <TextView 
 
     android:id="@+id/textTime" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_alignParentLeft="true" 
 
     android:layout_below="@+id/textView2" 
 
     android:layout_marginTop="40dp" 
 
     android:text="Large Text" 
 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 
 

 
</RelativeLayout>

+0

您将为每个后续元素添加更多和更多的余量。所以他们当然会越来越分开。你还期望什么? – 2015-04-06 09:11:54

回答

1

怎么一回事,因为你使用RelativeLayout,您只需拖放所有TextViews这就是为什么他们得到不同的利润率。现在试试这个。

<LinearLayout 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" 
tools:context="com.bustracker.MainActivity" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:text="Latitude:" 
    android:paddingLeft="10dp"/> 

<TextView 
    android:id="@+id/textLat" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:paddingLeft="10dp" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="10dp" 
    android:layout_marginTop="5dp" 
    android:text="Longitude:" /> 

<TextView 
    android:id="@+id/textLong" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:paddingLeft="10dp" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:paddingLeft="10dp" 
    android:text="Bus available wifi:" /> 

<TextView 
    android:id="@+id/textWifi" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:text="Large Text" 
    android:paddingLeft="10dp" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:paddingLeft="10dp" 
    android:text="Time stamp:" /> 

<TextView 
    android:id="@+id/textTime" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:paddingLeft="10dp" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

</LinearLayout>