Reputation: 2787
I am trying to add two different textviews with different heights like so:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/single_margin"
android:layout_marginLeft="@dimen/double_margin"
android:layout_marginRight="@dimen/double_margin"
android:layout_marginTop="@dimen/single_margin"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/newsfeed_ad_title"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_marginRight="28dp"
android:layout_weight="3"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:singleLine="false"
android:text="This is example text view that will mess up the height!"
android:textColor="@color/dark_blue"
android:textSize="@dimen/ad_title_text" />
<TextView
android:id="@+id/newsfeed_ad_info_button"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:background="@drawable/selector_rounded_box_light_blue"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:paddingBottom="@dimen/single_margin"
android:paddingLeft="@dimen/double_margin"
android:paddingRight="@dimen/double_margin"
android:paddingTop="@dimen/single_margin"
android:text="Learn More"
android:textColor="@color/dark_blue"
android:textSize="@dimen/body_text" /> </LinearLayout>
And the result is this:
(Don't mind the drop shadow above. I cropped the image and the shadow is from the actionbar)
The height of the linear layout is determined by the smaller textview instead of the bigger one. Why? And how do I go about fixing it? Thanks in advance
Upvotes: 3
Views: 4150
Reputation: 742
Make textview's height
wrap_content
it will solve the issue
android:id="@+id/newsfeed_ad_title"
android:layout_width="0px"
android:layout_height="wrap_content"
Upvotes: 6
Reputation: 683
The problem is that the first TextView
(the one with ID newsfeed_ad_title
) has an height of match_parent
. This means that first the LinearLayout
will compute its preferred height, and then the TextView
will occupy exactly that height.
Giving a wrap_content
to the first TextView
will solve the issue, because this way the LinearLayout
will first ask both children to compute their desired height,and then set his own accordingly.
<TextView
android:id="@+id/newsfeed_ad_title"
android:layout_width="0px"
android:layout_height="wrap_content"
... //the rest is unmodified
Upvotes: 0
Reputation: 1238
try this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/single_margin"
android:layout_marginLeft="@dimen/double_margin"
android:layout_marginRight="@dimen/double_margin"
android:layout_marginTop="@dimen/single_margin"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/newsfeed_ad_title"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_marginRight="28dp"
android:layout_weight="3"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:singleLine="false"
android:text="This is example text view that will mess up the height!"
android:textColor="@color/dark_blue"
android:textSize="@dimen/ad_title_text" />
<TextView
android:id="@+id/newsfeed_ad_info_button"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="2"
android:background="@drawable/selector_rounded_box_light_blue"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:paddingBottom="@dimen/single_margin"
android:paddingLeft="@dimen/double_margin"
android:paddingRight="@dimen/double_margin"
android:paddingTop="@dimen/single_margin"
android:text="Learn More"
android:textColor="@color/dark_blue"
android:textSize="@dimen/body_text" />
</LinearLayout>
If this does not solve your problem then give your dimen.xml file.
Hope this will be helpful...thanks
Upvotes: 1
Reputation: 24848
Try to set match_parent
newsfeed_ad_info_button
TextView :
<TextView
android:id="@+id/newsfeed_ad_info_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="2"
android:background="@drawable/selector_rounded_box_light_blue"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:paddingBottom="@dimen/single_margin"
android:paddingLeft="@dimen/double_margin"
android:paddingRight="@dimen/double_margin"
android:paddingTop="@dimen/single_margin"
android:text="Learn More"
android:textColor="@color/dark_blue"
android:textSize="@dimen/body_text" />
Note : Also use dp instead px : http://developer.android.com/guide/practices/screens_support.html
Upvotes: 0
Reputation: 813
You want to make the left textview (with ID newsfeed_ad_title) not cut right? Change the android:layout_height to "wrap_content"
Upvotes: 1