Android XML layout fit all screen?
-
I want this layout to fit properly on any android screen size.Please edit the code and post it. <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*"> <TableRow android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="100"> <EditText android:layout_width="fill_parent" android:layout_height="50dp" android:inputType="numberDecimal" android:ems="10" android:id="@+id/eText1" android:layout_column="0" android:layout_weight="50" /> <EditText android:layout_width="fill_parent" android:layout_height="50dp" android:inputType="numberDecimal" android:ems="10" android:id="@+id/eText2" android:layout_column="2" android:layout_weight="50" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="100"> <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ADDITION" android:id="@+id/add" android:layout_column="0" android:layout_weight="50" android:imeOptions="actionDone" /> <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SUBTRACTION" android:id="@+id/sub" android:layout_column="2" android:layout_weight="50" android:imeOptions="actionDone" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="100"> <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="MULTIPLICATION" android:id="@+id/mul" android:layout_column="0" android:layout_weight="50" android:imeOptions="actionDone" /> <Button style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="DIVISION" android:id="@+id/div" android:layout_column="2" android:layout_weight="50" android:imeOptions="actionDone" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="100"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/buttonStyleSmall" android:text="POWER" android:id="@+id/po" android:layout_column="0" android:layout_weight="50" android:imeOptions="actionDone" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/buttonStyleSmall" android:text="EXPONENT" android:id="@+id/ex" android:layout_column="2" android:layout_weight="50" android:imeOptions="actionDone" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="100"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text=" Result" android:textSize="25dp" android:id="@+id/textView" android:layout_column="0" android:layout_weight="50" android:padding="5dp" android:gravity="fill" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/editres" android:editable="false" android:layout_column="2" android:layout_weight="50" /> </TableRow> </TableLayout> </ScrollView>
-
Answer:
<?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:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1.2"> <EditText android:layout_width="50dp" android:layout_height="match_parent" android:inputType="numberDecimal" android:ems="10" android:id="@+id/eText1" android:layout_weight="1" /> <EditText android:layout_width="50dp" android:layout_height="match_parent" android:inputType="numberDecimal" android:ems="10" android:id="@+id/eText2" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <Button style="?android:attr/buttonStyleSmall" android:layout_width="match_parent" android:layout_height="match_parent" android:text="ADDITION" android:id="@+id/add" android:layout_weight="1" android:imeOptions="actionDone" /> <Button style="?android:attr/buttonStyleSmall" android:layout_width="match_parent" android:layout_height="match_parent" android:text="SUBTRACTION" android:id="@+id/sub" android:layout_weight="1" android:imeOptions="actionDone" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <Button style="?android:attr/buttonStyleSmall" android:layout_width="50dp" android:layout_height="match_parent" android:text="MULTIPLICATION" android:id="@+id/mul" android:layout_weight="50" android:imeOptions="actionDone" /> <Button style="?android:attr/buttonStyleSmall" android:layout_width="50dp" android:layout_height="match_parent" android:text="DIVISION" android:id="@+id/div" android:layout_weight="50" android:imeOptions="actionDone" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <Button android:layout_width="50dp" android:layout_height="match_parent" style="?android:attr/buttonStyleSmall" android:text="POWER" android:id="@+id/po" android:layout_weight="50" android:imeOptions="actionDone" /> <Button android:layout_width="50dp" android:layout_height="match_parent" style="?android:attr/buttonStyleSmall" android:text="EXPONENT" android:id="@+id/ex" android:layout_weight="50" android:imeOptions="actionDone" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1.2"> <TextView android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Result" android:textSize="25dp" android:id="@+id/textView" android:layout_weight="50" android:padding="5dp"/> <EditText android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/editres" android:inputType="none" android:layout_weight="50" /> </LinearLayout> </LinearLayout> </RelativeLayout> Now this might not be what you're looking for, but it does what I assume you'd like. This solution uses nested weights, which reduce rendering performance; the amount of performance degrade will depend on the host devices capabilities, but it really isn't noticeable unless the layout is somehow forced to refresh with a quick interval. Seeing as there aren't any static values associated with widths or heights, this layout will shrink and grow as necessary on any screen, this is thanks to using match_parent (fill_parent is as good as deprecated) and RelativeLayout root element, and a child vertically oriented LinearLayout replacing your TableLayout, with several nested LinearLayout elements replacing your rows.
Pol Osei at Quora Visit the source
Other answers
why not try android percent support library with percentage ratio feature for every widgets. Demo HERE@http://code2concept.blogspot.in/2015/08/android-percent-support-lib-sample.html Github Project HERE@https://github.com/nitiwari-dev/android-percent-layout-sample Really awesome !!!
Nitesh Tiwari
Related Q & A:
- What Are The Best Android Applications For Samsung Galaxy Fit?Best solution by samsung.com
- how to make my own home screen for android?Best solution by Stack Overflow
- How to increase brightness of screen on Android?Best solution by Stack Overflow
- How can i change my yahoo page to fit the screen?Best solution by Yahoo! Answers
- How do you fit a video to a screen?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.