Not Able To Align Two Text Views On The Same Line In Android
The xml file is,
Solution 1:
Your LinearLayout has vertical orientation. It should be horizontal to be able to place its children in the same line.
Solution 2:
try to change the layout to 'relative layout', and then play with the XML
Solution 3:
Please change your orientation from vertical to horizontal. Now your textviews will be oriented horizontally.
Solution 4:
use this code for designing xml
<?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:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Super power"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="@+id/lin1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
and add your dynamic text view in LinearLayout whoes id is "lin1" hope it will work for you
Solution 5:
Try this way :
<?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:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Super Powers : "
/>
<TextView
android:id="@+id/txt_on_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OFF" />
</LinearLayout>
</LinearLayout>
and in your java file take the reference of ON OFF textview like this :
TextView txtOnOff;
txtOnOff=(TextView)findViewById(R.id.txt_on_off);
txtOnOff.setText("ON");
thats all
Post a Comment for "Not Able To Align Two Text Views On The Same Line In Android"