I have an xml which uses linear layout and weights to equally distribute space on the screen to a few buttons and such. When I rotate screen to landscape mode, the buttons all get compressed. Could someone tell me how to make the buttons take equal space, non scrollable, when in portrait, and the whole screen scrollable when in landscape. Presently I am not using any scrollview and the layout is looking good, with the table and buttons taking the right amount of space, but when i rotate the screen to landscape, everything gets compressed. I tried enclosing the Linear Layout inside a scrollview but that caused the Linear Layout to move out of the screen, so when in portrait mode, i have to scroll to see whole content. Here is my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/linear"
android:orientation="vertical"
android:background="#bf000000"
tools:context=".MainActivity"
android:layout_above="#+id/imageView">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtReceive1"
android:visibility="gone"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/table"
android:background="#fff3f3f2"
android:stretchColumns="*"
android:shrinkColumns="*"
>
<TableRow>
<TextView
android:text="CH"
android:gravity="center"
android:padding="8dip"
android:layout_width="wrap_content" />
<TextView
android:text="kWh"
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content" />
<TextView
android:text="Load"
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content" />
<TextView
android:text="Date"
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content" />
</TableRow>
<TableRow >
<TextView
android:padding="8dip" android:layout_width="wrap_content"
android:gravity="center"
android:id="#+id/t11"
android:text="1" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t12" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t13" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t14" />
</TableRow>
<TableRow>
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t21"
android:text="2" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t22" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t23" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t24" />
</TableRow>
<TableRow>
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t31"
android:text="3" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t32" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content" />
<TextView
android:gravity="center"
android:padding="8dip"
android:layout_width="wrap_content"
android:id="#+id/t34" />
</TableRow> <TableRow>
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t41"
android:text="4" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t42" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t43" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t44" />
</TableRow>
<TableRow >
<TextView
android:padding="8dip" android:layout_width="wrap_content"
android:gravity="center"
android:id="#+id/t51"
android:text="5" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t52" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t53" />
<TextView
android:gravity="center"
android:padding="8dip" android:layout_width="wrap_content"
android:id="#+id/t54" />
</TableRow>
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff8c00"
android:padding="6dip"
android:id="#+id/txtReceive"
android:layout_below="#+id/table"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/lin2"
android:visibility="visible"
android:paddingTop="5dp"
android:weightSum="2">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:visibility="visible"
android:weightSum="4"
android:id="#+id/rel">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_height="fill_parent"
android:id="#+id/imageButton1"
android:layout_width="fill_parent"
android:background="#drawable/btn_01_small"
android:textColor="#ffa5ff45"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Channel"
android:textSize="22sp"
android:id="#+id/textView3"
android:layout_alignTop="#+id/imageButton1"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#ffa5ff45"
android:id="#+id/textView9"
android:textSize="22sp"
android:layout_alignBottom="#+id/imageButton1"
android:layout_centerHorizontal="true" />
</RelativeLayout><RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:id="#+id/imageButton2"
android:background="#drawable/btn_02"
android:textColor="#ffa5ff45"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="kWh"
android:textSize="22sp"
android:id="#+id/textView6"
android:layout_alignTop="#+id/imageButton2"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="000.0"
android:textColor="#ffa5ff45"
android:id="#+id/textView10"
android:textSize="22sp"
android:layout_alignBottom="#+id/imageButton2"
android:layout_centerHorizontal="true" />
</RelativeLayout><RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:id="#+id/imageButton3"
android:background="#drawable/btn_03"
android:textColor="#ffa5ff45"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load"
android:id="#+id/textView7"
android:textSize="22sp"
android:layout_alignTop="#+id/imageButton3"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="000"
android:textColor="#ffa5ff45"
android:id="#+id/textView11"
android:textSize="22sp"
android:layout_alignBottom="#+id/imageButton3"
android:layout_centerHorizontal="true" />
</RelativeLayout><RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:id="#+id/imageButton4"
android:background="#drawable/btn_04_small" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Days"
android:id="#+id/textView8"
android:textSize="22sp"
android:layout_alignTop="#+id/imageButton4"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="000"
android:textColor="#ffa5ff45"
android:id="#+id/textView12"
android:textSize="22sp"
android:layout_alignBottom="#+id/imageButton4"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_alignParentRight="true"
android:visibility="visible"
android:weightSum="4"
android:layout_below="#+id/txtReceive"
android:id="#+id/rel2">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_height="fill_parent"
android:id="#+id/imageButton12"
android:layout_width="fill_parent"
android:background="#drawable/btn_01_small"
android:textColor="#ffa5ff45"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Auto ON"
android:id="#+id/textView32"
android:textSize="22sp"
android:layout_alignTop="#+id/imageButton12"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00"
android:textColor="#ffa5ff45"
android:id="#+id/textView92"
android:textSize="22sp"
android:layout_alignBottom="#+id/imageButton12"
android:layout_centerHorizontal="true" />
</RelativeLayout><RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:id="#+id/imageButton22"
android:background="#drawable/btn_04_small"
android:textColor="#ffa5ff45"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Auto OFF"
android:textSize="22sp"
android:id="#+id/textView62"
android:layout_alignTop="#+id/imageButton22"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00"
android:textColor="#ffa5ff45"
android:id="#+id/textView102"
android:textSize="22sp"
android:layout_alignBottom="#+id/imageButton22"
android:layout_centerHorizontal="true" />
</RelativeLayout><RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:id="#+id/imageButton31"
android:layout_marginTop="7dp"
android:layout_marginBottom="-14dp"
android:background="#drawable/send_btn_01"
android:textSize="22sp"
android:text="SET TIME" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scaleType="matrix"
android:layout_marginBottom="-7dp"
android:id="#+id/imageButton32"
android:padding="0dp"
android:background="#drawable/send_btn_01"
android:textSize="22sp"
android:text="RECHARGE" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/base_irya_left1"
android:background="#bf000000"
android:adjustViewBounds="true"
android:layout_alignParentBottom="true" />
<!-- </RelativeLayout> -->
Did you consider using Fragments in Android. Here is a tutorial.
How to support different screensizes with fragments(See here)
It is possible to define in the layout file of an activity that it contains fragments (static definition) or to modify the fragments of an activity at runtime (dynamic definition).
To display differnet fragments in your activities based on the actual available space you can:
Use one activity, which displays two fragments for tablets and on handset devices. In this case change at runtime the fragments displayed by the activity whenever necessary. In this scenario you typically define instances of the FrameLayout class as placeholder in your layout and add the fragments at runtime to them.
Use separate activities to host each fragment on a handset. For example, when the tablet UI uses two fragments in an activity, use the same activity for handsets, but supply an alternative layout that includes just one fragment. If the detailed fragment is there, the main activity tells the fragment that it should update itself. If the detail fragment is not available, the main activity starts the detailed activity.
Which option to select depends on the use case, typical the dynamic contribution is more flexible bit a bit harder to implement.
Creating two xmls, one for landscape and one for portrait, will fix the issue. Portrait goes into res/layout folder and landscape goes into res/layout-land. The two should have identical names for this to work.
Related
How to display schedule like (Classes, Testes and so on) for college App Using a Timetable, for eg like this
I was thinking of extending FrameLayout and customize it in some way, Any help?
Thanks.
You can use TableLayout to design the desired view. According to documentation TableLayout is A layout that arranges its children into rows and columns. This I think is the best suit for you` as you have given number of rows and columns.
Here is an example of TableLayout you can extend to fit your needs:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<TableRow android:background="#0079D6" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="title 1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="title 2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="title 3" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Suresh Dasari" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hyderabad" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Rohini Alavala" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Guntur" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Trishika Dasari" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Guntur" />
</TableRow>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="I like to go out more than staying home."
android:textSize="10.5dp" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:gravity="center_vertical" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="Do you tend to over analyze everything, all the time?"
android:textSize="10.5dp" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center_vertical" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="You've made most of your decisions based on how you feel."
android:textSize="10.5dp" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center_vertical" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="You use past experiences to guide your decisions."
android:textSize="10.5dp" />
<Spinner
android:id="#+id/spinner4"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center_vertical" />
</TableRow>
</TableLayout>
</ScrollView>
<Button
android:id="#+id/calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
<TextView
android:id="#+id/personalitytype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Personality Type"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableLayout>
A picture of my applicaton can viewed here : http://tinypic.com/r/2uy1t3d/5
Hello, I'd like to add a scroll view to my questions in my application. This would include the TextViews and Spinners but not the Submit button on the bottom or the TextView below it. I understand you'd have to mess with the weight, but i'm not getting good results. Thanks
If you want the Button and TextViews below it to remain at the bottom, try putting everything in a RelativeLayout, wrapping your Buttons and TextViews in a LinearLayout and aligning it to the parent's bottom.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="I like to go out more than staying home."
android:textSize="10.5dp" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:gravity="center_vertical" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="Do you tend to over analyze everything, all the time?"
android:textSize="10.5dp" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center_vertical" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="You've made most of your decisions based on how you feel."
android:textSize="10.5dp" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center_vertical" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_marginLeft="5dp"
android:gravity="center_vertical"
android:text="You use past experiences to guide your decisions."
android:textSize="10.5dp" />
<Spinner
android:id="#+id/spinner4"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center_vertical" />
</TableRow>
</TableLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
<TextView
android:id="#+id/personalitytype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Personality Type"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</RelativeLayout>
Full disclaimer: Code not tested.
I have a button in linearlayout above the image. The image is displaying properly, but the linearlayout above the image is not displayed.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E9E0DB" >
<LinearLayout
android:id="#+id/editdialogstartedlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/profdialogphotoimageview"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="5dip" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Edit"
android:textColor="#000000" />
</LinearLayout>
<com.example.masonrytest.views.ScaleImageView
android:id="#+id/profdialogphotoimageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:id="#+id/textlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profdialogphotoimageview"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dip" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/profdialogphotoimageview"
android:text="There Is Nothing Negative In Total Exploitation Of Natural Resources. What Say?"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="normal" />
<LinearLayout
android:id="#+id/dialog_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<ImageView
android:id="#+id/list_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignBottom="#id/text1"
android:src="#drawable/picture1" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/list_image"
android:layout_toRightOf="#+id/list_image"
android:padding="5dip"
android:text="By Andrew"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="25dp"
android:src="#drawable/member" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dip"
android:text="8"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:src="#drawable/udebate_fav" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"
android:text="64"
android:textColor="#000000"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Any ideas or suggestions please?
Thanks.
Try it.
remove following property from LinearLayout.
android:layout_above="#+id/profdialogphotoimageview"
and put
android:layout_alignParentTop="true"
and also you need to put following property in "com.example.masonrytest.views.ScaleImageView"
android:layout_below="#+id/editdialogstartedlayout"
now you get the actual View which you need.
In your old code Your Button not view because of has fill-parent height so, it takes all size of the screen. and LinearLayout above of this layout that's why its gone above of the screen.
Your root level (the RelativeLayout) has children that all have fill_parent/match_parent. This means that all items are going to fill the available space. You will only see the last one (#+id/textlayout). Think about what you are trying to achieve with your layout.
If you use Eclipse, there is also a GUI you can test with.
Give id to main layout here RelativeLayout android:id="#+id/main"
and add
android:layout_below="#+id/main" to LinearLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E9E0DB" >
<LinearLayout
android:id="#+id/editdialogstartedlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="5dip"
android:layout_alignParentTop="true" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Edit"
android:textColor="#000000" />
</LinearLayout>
<com.example.masonrytest.views.ScaleImageView
android:id="#+id/profdialogphotoimageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editdialogstartedlayout" />
<LinearLayout
android:id="#+id/textlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profdialogphotoimageview"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dip" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="There Is Nothing Negative In Total Exploitation Of Natural Resources. What Say?"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="normal" />
<LinearLayout
android:id="#+id/dialog_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<ImageView
android:id="#+id/list_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignBottom="#id/text1"
android:src="#drawable/picture1" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/list_image"
android:layout_toRightOf="#+id/list_image"
android:padding="5dip"
android:text="By Andrew"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="25dp"
android:src="#drawable/member" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dip"
android:text="8"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:src="#drawable/udebate_fav" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"
android:text="64"
android:textColor="#000000"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
in the element com.example.masonrytest.views.ScaleImageView try adding the following line:
android:layout_toEndOf="#id/editdialogstartedlayout"
I have relative layout and inside it there are two linear layouts
the program works without the first linear layout. can any one explain why ?
<?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="#drawable/bngp" >
<TextView
android:id="#+id/Cart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="Cart"
android:textColor="#FFFFFF"
android:textSize="25sp"
android:textStyle="bold" />
// this is the linear layout causes error
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Cart"
android:orientation="horizontal" >
<TextView
android:id="#+id/Product"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="Product"
android:textColor="#000000" />
<TextView
android:id="#+id/Quantity"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="Quantity"
android:textColor="#000000" />
<TextView
android:id="#+id/Price"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Price"
android:textColor="#000000" />
<TextView
android:id="#+id/Value"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Value"
android:textColor="#000000" />
</LinearLayout>
// end of linear layout
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/textView1"
android:layout_below="#id/table" />
<TextView
android:id="#id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linear"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:text="Total Value: "
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/Final_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/linear"
android:layout_toRightOf="#id/textView1"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:textColor="#FFFFFF" />
<LinearLayout
android:id="#id/linear"
style="#android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Confirm" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Clear" />
</LinearLayout>
</RelativeLayout>
Check your layout now. I have edited some lines. use #+id instead of #id. You must know the difference between #id , #+id and #android:id.
ie,
"#android:id" which means you are referencing an item in Android namespace.
"#id" means you have defined ids in your application itself,
eg:-
===========================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="TextView1" type="id"/>
</resources>
in this case you have defined a textview id in your resources. Now you can use ,
<TextView
android:id="#id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
===========================================================
"#+id" means you are created a view (textview , layouts , etc..) in your layout and you wanted to add the id to R.java.
Check your layout now,
<?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="#drawable/bngp" >
<TextView
android:id="#+id/Cart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="Cart"
android:textColor="#FFFFFF"
android:textSize="25sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/Cart"
android:orientation="horizontal" >
<TextView
android:id="#+id/Product"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="6"
android:text="Product"
android:textColor="#000000" />
<TextView
android:id="#+id/Quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="Quantity"
android:textColor="#000000" />
<TextView
android:id="#+id/Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Price"
android:textColor="#000000" />
<TextView
android:id="#+id/Value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Value"
android:textColor="#000000" />
</LinearLayout>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/textView1"
android:layout_below="#+id/table" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linear"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:text="Total Value: "
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/Final_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linear"
android:layout_toRightOf="#+id/textView1"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:textColor="#FFFFFF" />
<LinearLayout
android:id="#+id/linear"
style="#android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Confirm" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Clear" />
</LinearLayout>
</RelativeLayout>
For starters, instead of using #id/blah, always use #+id/blah (even if you are not defining the view). It doesn't hurt, and can prevent some really hard to track down errors.
For more details, please provide the error you are receiving.
This is my first android application, I face a bunch of problems. I want to make a design like in this image:
I tried many solutions to do it, but nothing work.
This is my code:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<View
android:layout_height="2dip"
android:background="#color/dark_blue"/>
<!--Product information-->
<TableRow android:id="#+id/product_info">
<ImageView android:id="#+id/product_img"
android:src="#drawable/mdpi_product_verify_scan_code"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<TextView android:id="#+id/tvdesc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:text="description description description "
android:textColor="#color/black"
/>
</TableRow>
<View
android:layout_height="2dip"
android:background="#color/dark_blue"/>
<!--Images button-->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Product Description"
android:textColor="#color/black"
android:textAppearance="?android:textAppearanceMedium"
/>
<FrameLayout
android:background="#color/dark_blue"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:padding="5dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/mdpi_btn_show_images_icon"
android:background="#android:color/transparent"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Images"/>
</FrameLayout>
</TableRow>
<TableRow android:id="#+id/product_info">
<ImageView android:id="#+id/ima"
android:src="#drawable/mdpi_product_verify_scan_code"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<TextView android:id="#+id/tv2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:text="description description description "
android:textColor="#color/black"
/>
</TableRow>
<!--Verification -->
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="product verification"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#color/green"/>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This product can be verified. Tap on the VERIFY PRODUCT button above."
android:textColor="#color/green"/>
</TableRow>
</TableLayout>
and this the result
as you can see, all the elements are messed up
and the images button disappear also when i set the gravity left the images disappear and the text stay where they are, nothing change.
This image shows what are the problems:
How to make each text on a row.
Set the image at the left (the gravity left didn't work)
How to draw a vertical line?
How can i put image with the text?( i was using the span but it's work just for one row here i have two text rows, is there anyway to merge two vertical cells).
The images button disappear.
Thanks for any help.
I guess this should help you a bit understand how it works. I manage to do something that looks like what you might need
<?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="vertical" >
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tap to Verify Product" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="16dp"
android:src="#drawable/ic_launcher" />
<View
android:id="#+id/view1"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/imageView1"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignLeft="#+id/textView2"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView3"
android:layout_alignLeft="#+id/textView1"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_marginLeft="21dp"
android:layout_toRightOf="#+id/view1"
android:text="TextView" />
</RelativeLayout>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="46dp" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView" />
</LinearLayout>
Try it out in your IDE and from that, if you need further helps, I'll see what I can do.