Reputation: 2711
I have started learning android development and I have stumbled across a thing I don't quite understand why is it happening. Here is the code I am having trouble with:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/lbl_Title"
android:id="@+id/lbl_Title"
android:layout_marginTop="@dimen/activity_vertical_margin" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_weight="2"
android:layout_marginTop="@dimen/activity_vertical_margin" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/lbl_Title"
android:id="@+id/lbl_Date"
android:layout_marginTop="@dimen/activity_vertical_margin" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="-"
android:id="@+id/textView2"
android:layout_marginTop="@dimen/activity_vertical_margin" />/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Which results in the following:
As you can see, even though my two containers are exactly the same, for unknown reason text under the second container is located slightly above the first element. Why is this so?
P.S. These containers are under the RelativeLayout
panel.
Upvotes: 2
Views: 35
Reputation: 4969
I have changed some portions. Now its working as your requirement
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/lbl_Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/lbl_Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:textAppearance="?android:attr/textAppearanceLarge" />/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Upvotes: 1
Reputation: 897
The issue is the EditText
. Since you are only using wrap_content
on the second TestView
on the right side, the height of that linear layout is smaller than the one on the left.
Upvotes: 1