Android how to set the width of a view to a certain ratio of the width of the screen?



I create 3 TextViews placed horizontally in a LinearLayout. Now, I want them to averagely take up 1/3 of the width of screen respectively. In another word, the width of any TextView is determined by the width of the screen and the ratio is always 1/3.


I wonder if there's any way to achieve this target with only modifying the xml file?


main.xml:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView1" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView2" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView3" />

</LinearLayout>

No comments:

Post a Comment