View not showing properly in android layout
I am designing custom dialogue in android, For this purpose I designed xml file as
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@color/item_bg_color"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/custom_dialog_text"
android:textColor="#000000"
android:textSize="14dip"
android:typeface="serif"
android:singleLine="false"
android:text="You are not authorized to use this application."
android:layout_marginTop="10dip"/>
<Button android:id="@+id/custom_button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:layout_belo开发者_开发百科w="@+id/custom_dialog_text"
android:layout_toRightOf="@+id/custom_dialog_text"/>
</RelativeLayout>
Problem :
I want to show button at end (Right) of TextView, And textview's text should be in more than one line(if more characters have to show). But when I am using this layout, button is not appearing anywhere.
I used LinearLayout and TableLayout also and in both cases, button is appearing with a little part. Where am I wrong?
Basically you want to tell the button to be align to the right, take all the space it needs, then give the rest of the space to the TextView. You do this by specifying android:layout_layout_alignParentRight="true"
for the button and android:layout_toLeftOf="@id/custom_button_ok"
for the TextView. Mind the order!!!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@color/item_bg_color" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<Button android:id="@+id/custom_button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:layout_layout_alignParentRight="true" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/custom_dialog_text"
android:textColor="#000000"
android:textSize="14dip"
android:typeface="serif"
android:singleLine="false"
android:text="You are not authorized to use this application."
android:layout_marginTop="10dip"
android:layout_toLeftOf="@id/custom_button_ok"
/>
</RelativeLayout>
For Button add the attributes android:layout_alignParentRight,android:layout_below,they help you
try doin this..
<TextView android:layout_width="100dip"
android:layout_height="wrap_content"
android:id="@+id/custom_dialog_text"
android:textColor="#000000"
android:textSize="14dip"
android:typeface="serif"
android:singleLine="false"
android:text="You are not authorized to use this application."
android:layout_marginTop="10dip"/>
layout_belw and layout_rightof properties are set to same Id in text view.Just use layout_below.Also u can set gravity of button to bottom
Please try below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:weightSum="1.0">
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="0dp" android:layout_weight="0.85">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/custom_dialog_text"
android:textColor="#FFFFFF" android:textSize="14dip"
android:typeface="serif" android:singleLine="false"
android:text="You are not authorized to use zdsaddsad this application."
android:layout_marginTop="10dip" />
</RelativeLayout>
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="0dp" android:layout_weight="0.15">
<Button android:id="@+id/custom_button_ok"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Ok" />
</RelativeLayout>
</LinearLayout>
精彩评论