I have created an Android App that contains 10 TextView boxes and I have given each one a different background. When I run the app on my device, it crashes, if I use 10 different backgrounds. If I use only 8 different backgrounds to fill up the 10 TextView boxes, the app works fine. Why does this happen and how can I fix it?
EDIT:
Sorry for not adding code, but below is the xml file. Notice I add a background to each TextView from img1 to img10. If I load this on my device, the program will crash. If I changed img9 to img7 and img10 to img7, then it will work fine. I cannot figure out why this occurs and I checked the sizes. They do not add up to 16MB.
So, excuse my ignorance. I am new to android app creating, but I found that a OutOfMemory exception is being thrown. This does not make size, b/c my images are all under 100 KB.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8ad0e8"
tools:context=".Adamantium1" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:weightSum="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="60sp"
android:background="#drawable/img1"
android:textStyle="bold"
android:text="9" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="60sp"
android:textStyle="bold"
android:background="#drawable/img2"
android:text="9" />
<TextView
android:id="#+id/textView3"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:gravity="center"
android:textSize="60sp"
android:textStyle="bold"
android:background="#drawable/img3"
android:layout_weight="1"
android:text="9" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_below="#+id/linearLayout1"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp" >
<TextView
android:id="#+id/textView4"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:gravity="center"
android:textSize="60sp"
android:textStyle="bold"
android:background="#drawable/img4"
android:layout_weight="1"
android:text="9" />
<TextView
android:id="#+id/textView5"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="60sp"
android:textStyle="bold"
android:background="#drawable/img5"
android:text="9" />
<TextView
android:id="#+id/textView6"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="60sp"
android:textStyle="bold"
android:background="#drawable/img6"
android:text="9" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout2"
android:layout_below="#+id/linearLayout2"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp" >
<TextView
android:id="#+id/textView7"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="60sp"
android:textStyle="bold"
android:background="#drawable/img7"
android:text="9" />
<TextView
android:id="#+id/textView8"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="60sp"
android:textStyle="bold"
android:background="#drawable/img8"
android:text="9" />
<TextView
android:id="#+id/textView9"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="60sp"
android:textStyle="bold"
android:background="#drawable/img9"
android:text="7" />
</LinearLayout>
<EditText
android:id="#+id/editText1"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textView10"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:ems="1"
android:inputType="numberPassword" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView10"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_below="#+id/linearLayout3"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="9"
android:textSize="60sp"
android:background="#drawable/img10"
android:textStyle="bold" />
<Button
android:id="#+id/EnterPass"
style="?android:attr/buttonStyleSmall"
android:layout_width="90dp"
android:layout_height="40dp"
android:layout_alignBottom="#+id/editText1"
android:layout_marginLeft="21dp"
android:layout_toRightOf="#+id/editText1"
android:text="Enter" />
</RelativeLayout>
May be your images are too large to be held in the heap of per application in android which is 16 MB in 4.2 .
Possible solution is decrease your image size.
This is the best I can tell from your problem posted here.
Related
This is my first app so sorry I know its not that good. My english neither.
I got a problem with my xml design: I want 2 Buttons and 2 TextViews in one line and to fill the whole line. At the moment it looks like that:
but it gets even worse:
My code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
<!--
skipping additional rows of identical structure
-->
</LinearLayout>
The problem is that you use wrap_content on the children of the linear layout. there are 2 solutions to your problem one is to use match parent on the text views and add gravity centre to them like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="centre"
android:text="TextView" />
<TextView
android:id="#+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="centre"
android:text="TextView" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
And another solution is to use a constraint layout with allows you to spread the child views using chains.
If I understood correctly, you should try for each of your LinearLayout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4" // number of sub items
>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="#+id/textView11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<Button
android:id="#+id/button11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
Also, you should take a look at RecyclerViews and create your own adapter and rows. It will be much easier to deal with.
I'm new to JAVA and Android development.
Basically I would like to draw 8 equal rectangles (keyboard keys) to fit on 100% width.
As far as I know linearlayout doesn't support drawables, so sadly that piece of code doesn't work for me:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:weightSum="2">
<View
android:id="#+id/keyboardKey1"
android:background="#drawable/keyboard_key_white"
android:weight="1"
android:layout_width="0dip"
android:layout_height="200dp"
android:layout_alignTop="#+id/keyboardKeyC"
android:layout_toRightOf="#+id/keyboardKeyA" />
<View
android:id="#+id/keyboardKey2"
android:background="#drawable/keyboard_key_white"
android:weight="1"
android:layout_width="0dip"
android:layout_height="200dp"
android:layout_alignTop="#+id/keyboardKeyC"
android:layout_toRightOf="#+id/keyboardKeyA" />
</LinearLayout>
Here are the contents of keyboard_key_while.xml as well:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff" />
<stroke
android:width="1dp"
android:color="#000" />
</shape>
As far as I know, I also can't do the the other way round and use linearlayout inside of the drawable XML. Can you give me suggestions of how to achieve that?
Thank you!
I did this before. Let me check my code to see if I still have it.
I found it. The layout I created is for a calculator. I wanted the buttons to scale according to screen size.
I used a TextView with solid white background for the buttons. I'm sure you could use a drawable for a background as well. Anyway, have a look at the way I did the LinearLayouts.
The Code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:background="#ffffffff"
>
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_weight="3"
android:background="#ffffff"
android:text="Food"
android:gravity="center|right"
android:paddingRight="0dp"
android:singleLine="true"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<RelativeLayout
android:id="#+id/more"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#drawable/layer_list_arrow_dn"
android:gravity="center"
android:singleLine="true"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:background="#ffffffff"
>
<TextView
android:id="#+id/amount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_weight="3"
android:background="#ffffff"
android:text="0.00"
android:gravity="center|right"
android:paddingRight="0dp"
android:singleLine="true"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<RelativeLayout
android:id="#+id/clear"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#drawable/layer_list_clear"
android:gravity="center"
android:singleLine="true"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:background="#00fcb514"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="0dp"
android:layout_marginRight="5dp"
android:background="#00333333"
>
<TextView
android:id="#+id/b00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:background="#drawable/ripple_holo_blue_bright"
android:text="7"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="4"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="1"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:background="#ffffff"
android:text=""
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#00666666"
>
<TextView
android:id="#+id/b10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="8"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="5"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="2"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:background="#ffffff"
android:text="0"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#00999999"
>
<TextView
android:id="#+id/b20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="9"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="6"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#ffffff"
android:text="3"
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b23"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:background="#ffffff"
android:text="."
android:gravity="center"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="0dp"
android:background="#00cccccc"
>
<TextView
android:id="#+id/b30"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:textSize="27sp"
android:textStyle="bold"
android:background="#drawable/layer_list_arrow_up"
android:onClick="onViewClick"
/>
<TextView
android:id="#+id/b31"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/layer_list_arrow_dn"
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:textSize="27sp"
android:textStyle="bold"
android:onClick="onViewClick"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can do that with a LinearLayout set to horizontal orientation and have each view inside that set an equal layout_weight and zero layout_width. You were almost there but you have to use layout_weight instead of weight.
This shows two keys taking up the width of the screen. If you put 8 views in there it scales accordingly.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:id="#+id/keyboardKey1"
android:layout_width="0dip"
android:layout_height="200dp"
android:layout_weight="1"
android:background="#drawable/keyboard_key_white" />
<View
android:id="#+id/keyboardKey2"
android:layout_width="0dip"
android:layout_height="200dp"
android:layout_weight="1"
android:background="#drawable/keyboard_key_white" />
</LinearLayout>
Two more things
in your example you are using RelativeLayout layout parameters in the keyboard views (layout_alignTop and layout_toRightOf). However the keyboard views are being hosted by a LinearLayout and are therefore ignored so they can be left out.
Another way to do this is to use the GridLayout where you can specify how many columns and rows you want. Inside the GridLayout you specify for each child view in which column and row you want it to appear with layout_column and layout_row.
Read up on Layouts on the Android Developer API Guides.
I have to design an application for 10 inch tab in Android.But when i run the application the design is in blur or not clear .I don't know why. I have also declare the android:screenOrientation="portrait" in manifest .How to design properly and where I'm doing wrong in xml file.Thanks in advance.
Here is my xml file code
<?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"
android:background="#android:color/white" >
<ImageView
android:id="#+id/imageLogoBBT"
android:layout_width="400dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/banya_tree_logo" />
<ImageView
android:id="#+id/imageButtonBack"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="15dp"
android:layout_marginTop="18dp"
android:contentDescription="#string/desc"
android:scaleType="fitCenter"
android:src="#drawable/back_img" />
<RelativeLayout
android:id="#+id/relImagLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/imageLogoBBT"
android:background="#drawable/inner_back"
android:padding="5dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6E9E9" >
<TextView
android:id="#+id/textViewTitle"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/APPLICATION_FOR_FUND_TRANSFER"
android:textColor="#32241F"
android:textSize="25sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/APPLICANTS_INFORMATION_Detail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewTitle"
android:layout_marginLeft="10dp"
android:text="#string/APPLICANTS_INFORMATION"
android:textColor="#32241F"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/linearScroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/lastrowLayout"
android:layout_below="#+id/APPLICANTS_INFORMATION_Detail"
android:baselineAligned="false"
android:orientation="horizontal" >
<ScrollView
android:id="#+id/scrollFormOne"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:baselineAligned="false"
android:orientation="vertical"
android:padding="2dp" >
<LinearLayout
android:id="#+id/linearlayout_One"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearlayout_textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginTop="5dp"
android:layout_weight="0.10"
android:gravity="left"
android:text="#string/title"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<TextView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginTop="5dp"
android:layout_weight="0.25"
android:gravity="left"
android:paddingLeft="5dp"
android:text="#string/last_name"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<TextView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginTop="5dp"
android:layout_weight="0.25"
android:gravity="left"
android:paddingLeft="5dp"
android:text="#string/first_name"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout_EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:baselineAligned="false"
android:orientation="horizontal" >
<Spinner
android:id="#+id/gps_spinnertitleName"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:layout_weight="0.10"
android:background="#drawable/button_shape"
android:gravity="center"
android:inputType="text"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<EditText
android:id="#+id/gps_edittextLastName"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_weight="0.25"
android:background="#drawable/button_shape"
android:gravity="left"
android:inputType="text"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<EditText
android:id="#+id/gps_editTextFirst"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_weight="0.25"
android:background="#drawable/button_shape"
android:gravity="left"
android:inputType="text"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scrollFrorm_Two"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:baselineAligned="false"
android:orientation="vertical"
android:padding="2dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/Beneficiary_Address"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<EditText
android:id="#+id/gspET_Beneficiary_Address"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_shape"
android:inputType="textMultiLine"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#241444"
android:textSize="19sp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/Beneficiary_Account_No"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<EditText
android:id="#+id/gspET_Beneficiary_Account_No"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_shape"
android:inputType="number"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#241444"
android:textSize="19sp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/Beneficiary_Bank_Name"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<EditText
android:id="#+id/gspET_Beneficiary_Bank_Name"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_shape"
android:inputType="text"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#241444"
android:textSize="19sp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/Beneficiary_Bank_Address"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<EditText
android:id="#+id/gspET_Beneficiary_Bank_Address"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_shape"
android:inputType="textMultiLine"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#241444"
android:textSize="19sp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/BIC_Chips_ID_BSB_Code_Fed_Wire_ABA_Sort_Code"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<EditText
android:id="#+id/gspET_BIC_Chips_ID_BSB"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_shape"
android:inputType="text"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#241444"
android:textSize="19sp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/Intermediary_Bank_Name"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<EditText
android:id="#+id/gspET_Intermediary_Bank_Name"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_shape"
android:inputType="text"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#241444"
android:textSize="19sp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="#string/Intermediary_Bank_Address"
android:textColor="#241444"
android:textSize="19sp"
android:textStyle="normal" />
<EditText
android:id="#+id/gspET_Intermediary_Bank_Address"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_shape"
android:inputType="textMultiLine"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="#241444"
android:textSize="19sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/lastrowLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="7dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="10dp" >
<CheckBox
android:id="#+id/android"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text="#string/I_Accept_Terms_Conditions"
android:textColor="#android:color/black" />
<ImageView
android:id="#+id/buttonSubmit_Next"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="0.40"
android:contentDescription="#string/desc"
android:src="#drawable/next_btton" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Screen Shot 2014-06-24 at 4.05.30 PM
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
// your left side part
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
// your right side part
</LinearLayout>
</LinearLayout>
and also use different images for 10 inch tablets
Do not scale the images using layout_width or layout_height by your self. I can see in the ImageView you have specified dp values, this will make system to scale your image which may cause blur. Instead use size and density-specific resources inside drawable folders like
res/drawable-mdpi/icon.png //for medium-density screens
res/drawable-hdpi/icon.png //for high-density screens
You can create specific layout suitable to the screen size and palce it in res\layout-xxx folders
Wherever possible use 9-patch images
If you have only one image and have to be scaled for different screen then use highest resolution image and keep it in drawable-nodpi folder and specify either height or width and lets system decide other so that image get scaled properly.
Read : http://developer.android.com/guide/practices/screens_support.html#screen-independence
Image scaling: http://argillander.wordpress.com/2011/11/24/scale-image-into-imageview-then-resize-imageview-to-match-the-image/
I added 11 to 12 column in List view, but I am not able to see all columns. While I scroll list_view will be able to see all columns. Can someone give me ideas how to do this? Here is my XML file code:
ListView Item Xml File
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:scrollbars="vertical" >
<TextView
android:id="#+id/textView1_ID"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView2_Name"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView3_Email"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView4_Mobile"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView5_Products"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView6_Budget"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView7Priority"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView8_Status"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView9_Notes"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView10_Date_Reminder"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView11_Time_Reminder"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView12_AddToContact"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
</TableRow>
</TableLayout>
And here is my ListView Code xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="#string/search_hint" >
<requestFocus />
</EditText>
<ListView
android:id="#+id/listView_DisplayData"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1" >
</ListView>
</RelativeLayout>
You can convert the ListView into a ScrollView and put all your content in there.
Or you create your own ListViewAdapter (or take an existing one such as the ArrayAdapter) and let the adapter insert your data into your listview.
For the latter option, your Activity needs to extend ListActivity and your listview should have the id android.R.id.list.
Please have a look at the following code
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF"
android:gravity="right"
android:padding="5dp"
android:paddingBottom="5dp"
android:stretchColumns="1,2,3"
tools:context=".MainActivity" >
<TableRow
android:id="#+id/tableRow0"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/billTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="5dp"
android:text="#string/billTextView"
android:textColor="#000" />
<EditText
android:id="#+id/billEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:layout_weight="1"
android:inputType="numberDecimal"
android:longClickable="false" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tenTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_weight="1"
android:gravity="center"
android:text="10%"
android:textColor="#000" />
<TextView
android:id="#+id/fifteenTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="15%"
android:textColor="#000" />
<TextView
android:id="#+id/twentyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="20%"
android:textColor="#000" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tipTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="5dp"
android:text="#string/tipTxtView"
android:textColor="#000" />
<EditText
android:id="#+id/tip10EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:gravity="center"
android:longClickable="false"
android:textSize="14sp" />
<EditText
android:id="#+id/tip15EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:gravity="center"
android:longClickable="false"
android:textSize="14sp" />
<EditText
android:id="#+id/tip20EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:gravity="center"
android:longClickable="false"
android:textSize="14sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/totalTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="5dp"
android:text="#string/totalTextView"
android:textColor="#000" />
<EditText
android:id="#+id/total10EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:gravity="center"
android:longClickable="false"
android:textSize="14sp" />
<EditText
android:id="#+id/total15EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:gravity="center"
android:longClickable="false"
android:textSize="14sp" />
<EditText
android:id="#+id/total20EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:gravity="center"
android:longClickable="false"
android:textSize="14sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/customTextView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right|center_vertical"
android:padding="5dp"
android:text="#string/customTextView"
android:textColor="#000" />
<SeekBar
android:id="#+id/customSeekBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:layout_weight="1"
android:focusable="false"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:progress="18" />
<TextView
android:id="#+id/customTipTextView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:text="a"
android:textColor="#000" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tipCustomTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="5dp"
android:text="#string/tipCustomTextView"
android:textColor="#000" />
<EditText
android:id="#+id/tipCustomEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:gravity="center"
android:longClickable="false"
android:textSize="14sp" />
<TextView
android:id="#+id/totalCustomTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|right"
android:padding="5dp"
android:text="#string/totalCustomTextView"
android:textColor="#000" />
<EditText
android:id="#+id/totalCustomEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:gravity="center"
android:longClickable="false"
android:textSize="14sp" />
</TableRow>
</TableLayout>
The project is created using Android Version 3.2.
This is how it get displayed in Galaxy Nexus, which is set to Android version 2.3.3
This is how it get displayed in Galaxy Nexus, which is set to Android version 3.2
As you can see, in that new version one, the GUI is bit upset. It seems like the components are overlapping. That is why it doesn't show the borders of the components. Please help!
Yep, this is normal. The visual appearance of Android has been greatly polished with Android 4.0. It has nothing to do with your code directly. Android does this automatically.
If you want all your users to see the old style, you can set down the targetVersion within the <uses-sdk> tag of your manifest file. However, I discourage you from doing this.