Why the rows in my LinearLayout are not put at the top? - android

I have a complex layout in XML.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/mainbackground"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
android:id="#+id/selector"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
style="#style/T2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:text="#string/month" />
<TextView
android:id="#+id/byday"
style="#style/T2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#color/tertiarybackground"
android:gravity="center"
android:text="#string/day"
android:textColor="#color/links" />
</LinearLayout>
<RelativeLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="#+id/selector"
android:layout_weight="0.1"
android:background="#color/mainbackground" >
<RelativeLayout
android:id="#+id/previous"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentLeft="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/arrow_left" />
</RelativeLayout>
<TextView
android:id="#+id/title"
style="#style/H2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dip"
android:textColor="#000000" />
<RelativeLayout
android:id="#+id/next"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentRight="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/arrow_right" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/daysoftheweek"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/header"
android:layout_weight="0.05"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="#style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sun" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="#style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mon" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="#style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tue" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="#style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/wed" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="#style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/thu" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="#style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fri" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="#style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sat" />
</LinearLayout>
</LinearLayout>
<GridView
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="#+id/daysoftheweek"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:listSelector="#android:color/transparent"
android:numColumns="7"
android:stretchMode="columnWidth" />
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:fadeScrollbars="false"
android:gravity="top"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="0" >
<LinearLayout
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_gravity="top"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
Now programatically I add rows to the LinearLayout text:
rLayout = (LinearLayout) findViewById(R.id.text);
View row = li.inflate(R.layout.event_row, null);
rLayout.addView(row);
This is the result I get.
As you can see the row are placed in the center, not at the top of the text LinearLayout
Thanks for your help!

Use layout_gravity="top" attribute for the LinearLayout.
<LinearLayout
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_gravity="top"
android:orientation="vertical" >
</LinearLayout>

SOLVED!
The problem was in the GridView above:
I changed form:
<GridView
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="#+id/daysoftheweek"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:listSelector="#android:color/transparent"
android:numColumns="7"
android:stretchMode="columnWidth" />
to
<GridView
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/daysoftheweek"
android:layout_gravity="center_horizontal"
android:listSelector="#android:color/transparent"
android:numColumns="7"
android:stretchMode="columnWidth" />

Related

Image is not fitted in webview's height

I am using an Activity having theme dialog. In that Activity's layout I have a WebView and I am loading an Image into it. But image is exceeding the height not fit properly. But I want to fit the image's height as WebView's height. I am sharing my code snippet and please tell me how can I overcome this problem.
Code snippet of Activity
myWebView.setBackgroundColor(0 * 00000000);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setDisplayZoomControls(false);
myWebView.getSettings().setLoadsImagesAutomatically(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
myWebView.loadUrl(image1);
myWebView.refreshDrawableState();
I am giving full Xml layout
<?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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#CC000000"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.56" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#000"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight=".27"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1.8"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="50sp"
android:layout_height="50sp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginBottom="2sp"
android:layout_marginLeft="3sp"
android:background="#drawable/load" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/imageView1"
android:text="UserName"
android:textColor="#fff"
android:textSize="15sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_marginRight="10sp"
android:text="Time"
android:textColor="#fff"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_lay"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight=".55"
android:background="#drawable/load"
android:orientation="vertical" >
<WebView
android:id="#+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/load"
android:fadingEdge="none"
android:overScrollMode="never"
android:scrollbars="none" />
<SurfaceView
android:id="#+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RelativeLayout
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:alpha=".9"
android:visibility="gone" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50sp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#dedcdc" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.7" >
<Button
android:id="#+id/btn_start"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="5sp"
android:background="#drawable/play_icon" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.8"
android:gravity="right" >
<TextView
android:id="#+id/txt_start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="00.00"
android:textColor="#000"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.2" >
<SeekBar
android:id="#+id/songProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dip"
android:progressDrawable="#drawable/red_scrubber_progress"
android:thumb="#drawable/red_scrubber_control" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.8" >
<TextView
android:id="#+id/txt_end_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="00.00"
android:textColor="#000"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1.6"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:fadingEdge="none"
android:fillViewport="true"
android:overScrollMode="never" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.creepster.LinkEnabledTextView
android:id="#+id/text_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:paddingTop="8sp"
android:text=""
android:textColor="#fff"
android:textSize="12sp"
android:textStyle="normal" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1.51"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_home"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/home_black_bg"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_search"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/search"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/srcollimage"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_love"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/activity"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_me"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/me"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>

android button is not showing after I put it in a scrollview

so I had to make a layout where it contains 4 expandables and below those expandables is a imagebutton and below that is 1 edit text and below that is several textviews than 2 imagebuttons on the bottom.
But somehoww those two buttons aren't showing. I'm guessing the issue is with the height, I tried to change the height but still not working.
these are the codes :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99cc00"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="30dp"
android:layout_marginTop="50dp"
android:background="#333333"
android:orientation="vertical"
android:weightSum="8" >
<TextView
android:id="#+id/nama"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ExpandableListView
android:id="#+id/EVkonsumsi_user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_weight="1" >
</ExpandableListView>
<ExpandableListView
android:id="#+id/EVprotein"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_weight="1" >
</ExpandableListView>
<ExpandableListView
android:id="#+id/EVsayur"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_weight="1" >
</ExpandableListView>
<ExpandableListView
android:id="#+id/EVkacang"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_weight="1" >
</ExpandableListView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="3" >
<ImageButton
android:id="#+id/buttonTambah"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#393939" />
<TextView
android:id="#+id/InputMenuMakanan"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false"
android:ems="10"
android:gravity="center"
android:text="Lainnya"
android:textColor="#ffffff"
android:textStyle="bold"
android:typeface="normal" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="9dp"
android:layout_weight="4" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="4" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="3" >
<EditText
android:id="#+id/gram"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:inputType="number"
android:textSize="12sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="8" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Kalori" />
<TextView
android:id="#+id/takaranKalori"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Protein" />
<TextView
android:id="#+id/takaranProtein"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Karbohidrat" />
<TextView
android:id="#+id/takaranKarbohidrat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Takaran" />
<TextView
android:id="#+id/jenisTakaran"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="LemakTotal" />
<TextView
android:id="#+id/takaranLemakTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Makanan" />
<TextView
android:id="#+id/namaMakanan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="takaranKolesterol" />
<TextView
android:id="#+id/takaranKolesterol"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="takaranSodium" />
<TextView
android:id="#+id/takaranSodium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="6" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="KaloriTotal" />
<TextView
android:id="#+id/takaranKaloriTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ProteinTotal" />
<TextView
android:id="#+id/takaranProteinTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="KarbohidratTotal" />
<TextView
android:id="#+id/takaranKarbohidratTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="SodiumTotal" />
<TextView
android:id="#+id/takaranSodiumTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="LemakTotalTotal" />
<TextView
android:id="#+id/takaranLemakTotalTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="KolesterolTotal" />
<TextView
android:id="#+id/takaranKolesterolTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<FrameLayout
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_marginLeft="28.5dp"
android:layout_marginRight="28.5dp"
android:layout_marginTop="10dp"
android:layout_weight="1" >
<ImageButton
android:id="#+id/buttonCancel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#393939" />
<TextView
android:id="#+id/InputMenuMakanan"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false"
android:ems="10"
android:gravity="center"
android:text="Cancel"
android:textColor="#ffffff"
android:textStyle="bold"
android:typeface="normal" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_marginLeft="28.5dp"
android:layout_marginRight="28.5dp"
android:layout_marginTop="10dp"
android:layout_weight="1" >
<ImageButton
android:id="#+id/buttonDone"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#393939" />
<TextView
android:id="#+id/InputMenuMakanan"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false"
android:ems="10"
android:gravity="center"
android:text="Next"
android:textColor="#ffffff"
android:textStyle="bold"
android:typeface="normal" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
any help would be appreciated. thanks!
// Try this way,hope this will help you to solve your problem...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#99cc00"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="30dp"
android:layout_marginTop="50dp"
android:background="#333333"
android:orientation="vertical"
android:weightSum="8" >
<TextView
android:id="#+id/nama"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ExpandableListView
android:id="#+id/EVkonsumsi_user"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="30dp"
android:layout_weight="1" >
</ExpandableListView>
<ExpandableListView
android:id="#+id/EVprotein"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="30dp"
android:layout_weight="1" >
</ExpandableListView>
<ExpandableListView
android:id="#+id/EVsayur"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="30dp"
android:layout_weight="1" >
</ExpandableListView>
<ExpandableListView
android:id="#+id/EVkacang"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="30dp"
android:layout_weight="1" >
</ExpandableListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical">
<ImageButton
android:id="#+id/buttonTambah"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#393939" />
<TextView
android:id="#+id/InputMenuMakanan"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:clickable="false"
android:ems="10"
android:gravity="center"
android:text="Lainnya"
android:textColor="#ffffff"
android:textStyle="bold"
android:typeface="normal" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="9dp"
android:layout_weight="4" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="4" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="3" >
<EditText
android:id="#+id/gram"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:inputType="number"
android:textSize="12sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="8" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Kalori" />
<TextView
android:id="#+id/takaranKalori"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Protein" />
<TextView
android:id="#+id/takaranProtein"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Karbohidrat" />
<TextView
android:id="#+id/takaranKarbohidrat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Takaran" />
<TextView
android:id="#+id/jenisTakaran"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="LemakTotal" />
<TextView
android:id="#+id/takaranLemakTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Makanan" />
<TextView
android:id="#+id/namaMakanan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="takaranKolesterol" />
<TextView
android:id="#+id/takaranKolesterol"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="takaranSodium" />
<TextView
android:id="#+id/takaranSodium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="6" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="KaloriTotal" />
<TextView
android:id="#+id/takaranKaloriTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ProteinTotal" />
<TextView
android:id="#+id/takaranProteinTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="KarbohidratTotal" />
<TextView
android:id="#+id/takaranKarbohidratTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="SodiumTotal" />
<TextView
android:id="#+id/takaranSodiumTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="LemakTotalTotal" />
<TextView
android:id="#+id/takaranLemakTotalTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="KolesterolTotal" />
<TextView
android:id="#+id/takaranKolesterolTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
<FrameLayout
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_marginLeft="28.5dp"
android:layout_marginRight="28.5dp"
android:layout_marginTop="10dp"
android:layout_weight="1" >
<ImageButton
android:id="#+id/buttonCancel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#393939" />
<TextView
android:id="#+id/InputMenuMakana"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:ems="10"
android:gravity="center"
android:text="Cancel"
android:textColor="#ffffff"
android:textStyle="bold"
android:typeface="normal" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_marginLeft="28.5dp"
android:layout_marginRight="28.5dp"
android:layout_marginTop="10dp"
android:layout_weight="1" >
<ImageButton
android:id="#+id/buttonDone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#393939" />
<TextView
android:id="#+id/InputMenuMaka"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:ems="10"
android:gravity="center"
android:text="Next"
android:textColor="#ffffff"
android:textStyle="bold"
android:typeface="normal" />
</FrameLayout>
</LinearLayout>
</LinearLayout>

Android : prevent edittext from hiding behind keyboard without changing manifest

Soft keyboard hides my edit text
this is my layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#F7F7F7"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="#C2C2C2"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:id="#+id/toggle1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="20dp"
android:layout_height="15dp"
android:src="#drawable/img1" />
</LinearLayout>
<LinearLayout
android:id="#+id/toggle2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="20dp"
android:layout_height="25dp"
android:src="#drawable/img2" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.65"
android:weightSum="1" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="horizontal" >
<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:background="#fff"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=""
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="#+id/list1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.15"
android:background="#EEEEEE"
android:padding="5dp"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="1" >
<EditText
android:id="#+id/addCmntTextField"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginTop="2dp"
android:layout_weight="0.8"
android:hint="Add a Comment"
android:text=""
android:textSize="11dp" />
<Button
android:layout_width="0dp"
android:layout_height="55dp"
android:layout_marginLeft="5dp"
android:layout_weight="0.2"
android:text="Save"
android:clickable="true" />
</LinearLayout>
</LinearLayout>
in my menifest is wrote android:windowSoftInputMode="stateHidden" and i cant change it otherwise it will efect my app.How can i do it please help.
This is my complete code
Just implement a nesting in Layouts and this will solve the problem. Try doing this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="20dp"
android:gravity="bottom"
android:weightSum="1">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id=#+id/addCmntTextField"
android:layout_weight="1"
android:hint="Add a Comment"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:id="#+id/saveComment"/>
</LinearLayout>
</LinearLayout>
Here is the solution that worked for me on samsung galaxy tab
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#F7F7F7"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#C2C2C2"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:id="#+id/toggle1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="20dp"
android:layout_height="15dp"
android:src="#drawable/img1" />
</LinearLayout>
<LinearLayout
android:id="#+id/toggle2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="20dp"
android:layout_height="25dp"
android:src="#drawable/img2" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="1" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="horizontal" >
<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:background="#fff"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=""
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="#+id/list1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="75dp"
android:background="#EEEEEE"
android:padding="5dp"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="1" >
<EditText
android:id="#+id/addCmntTextField"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginTop="2dp"
android:layout_weight="0.8"
android:hint="Add a Comment"
android:text=""
android:textSize="11dp" />
<Button
android:layout_width="0dp"
android:layout_height="55dp"
android:layout_marginLeft="5dp"
android:layout_weight="0.2"
android:text="Save"
android:clickable="true" />
</LinearLayout>
</LinearLayout>

Equal vertically spaced columns layout

I want to make this layout on my main screen of my application.
I have stripes for each image block shown above.
Please guide my which layout (RelativeLayout, LinearLayout...etc) should I use to achieve this.
I am new to android development. I have experimented few layout but not having success. I also used FrameLayout
<?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="fill_parent"
android:stretchColumns="1">
<TableRow>
<FrameLayout
android:id="#+id/inboxLargeButton"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/inbox_normal"
android:id="#+id/buttonWeddingDayCheatSheet"
android:layout_gravity="center_horizontal">
</ImageView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="2631"
android:layout_gravity="bottom"
android:gravity="center"
android:textColor="#fff"
android:textSize="50dp" />
</FrameLayout>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/outbox_normal"
android:id="#+id/buttonShareFavoriteRecipe"
android:layout_gravity="center_horizontal">
</ImageView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="0296"
android:layout_gravity="bottom"
android:gravity="center"
android:textColor="#fff"
android:textSize="50dp" />
</FrameLayout>
</TableRow>
<TableRow>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/header_left_normal"
android:id="#+id/buttonWeddingDayCheatSheet"
android:layout_gravity="center_horizontal">
</ImageView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Most sent"
android:layout_gravity="bottom"
android:gravity="center"
android:textColor="#fff"
android:textSize="15dp" />
</FrameLayout>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/header_right_normal"
android:id="#+id/buttonShareFavoriteRecipe"
android:layout_gravity="center_horizontal">
</ImageView>
</FrameLayout>
</TableRow>
<TableRow>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/body_left_normal"
android:id="#+id/buttonWeddingDayCheatSheet"
android:layout_gravity="center_horizontal">
</ImageView>
</FrameLayout>
<FrameLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/body_right_normal"
android:id="#+id/buttonShareFavoriteRecipe"
android:layout_gravity="center_horizontal">
</ImageView>
</FrameLayout>
</TableRow>
</TableLayout>
As I want to make the each block clickable too.
Try this code:
<?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:stretchColumns="1" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/inboxLargeButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/buttonWeddingDayCheatSheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" >
</ImageView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:text="2631"
android:textColor="#fff"
android:textSize="50dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/buttonShareFavoriteRecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" >
</ImageView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:text="0296"
android:textColor="#fff"
android:textSize="50dp" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/buttonWeddingDayCheatSheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" >
</ImageView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:text="Most sent"
android:textColor="#fff"
android:textSize="15dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/buttonShareFavoriteRecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" >
</ImageView>
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/buttonWeddingDayCheatSheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" >
</ImageView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/buttonShareFavoriteRecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" >
</ImageView>
</LinearLayout>
</TableRow>
</TableLayout>

layout_weight for RelativeLayout doesn't work

There is the following code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.9"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/activityEvaluationYesterdayValueDisplay"
android:layout_width="15dip"
android:layout_height="wrap_content"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<com.ulnda.mypsych.views.VerticalSeekBar
android:id="#+id/activityEvaluationYesterdayValue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:max="10"
android:progress="0" />
</LinearLayout>
Now I need to change LinearLayout to RelativeLayout. If I do it then RelativeLayout fill the whole screen, and it's bad. I understand that RelativeLayout doesn't use layout_weight for its work. Please, tell me, how can I fix it? I've tried to make LinearLayout wrapper for RelativeLayout, but it doesn't help.
UPDATE:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.6"
android:orientation="vertical" >
<RelativeLayout
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
</LinearLayout>
</LinearLayout>
UPDATE 2: FUll code
<?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" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.5" >
<LinearLayout
android:weightSum="1.0"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.9">
<TextView
android:id="#+id/activityEvaluationYesterdayValueDisplay"
android:layout_width="15dip"
android:layout_height="wrap_content"
android:text="0"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/activityEvaluationYesterdayValue"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<com.ulnda.mypsych.views.VerticalSeekBar
android:id="#+id/activityEvaluationYesterdayValue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:max="10"
android:progress="0" />
</RelativeLayout>
<TextView
android:id="#+id/TextView05"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.1"
android:gravity="center"
android:text="Yesterday"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.9"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/activityEvaluationTodayValueDisplay"
android:layout_width="20dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<com.ulnda.mypsych.views.VerticalSeekBar
android:id="#+id/activityEvaluationTodayValue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:max="10"
android:progress="0" />
</LinearLayout>
<TextView
android:id="#+id/TextView03"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.1"
android:gravity="center"
android:text="Today"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.9"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/activityEvaluationTomorrowValueDisplay"
android:layout_width="20dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<com.ulnda.mypsych.views.VerticalSeekBar
android:id="#+id/activityEvaluationTomorrowValue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:max="10"
android:progress="0" />
</LinearLayout>
<TextView
android:id="#+id/TextView02"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.1"
android:gravity="center"
android:text="Tomorrow"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="0.5" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.9"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/activityEvaluationEnergyValueDisplay"
android:layout_width="20dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<com.ulnda.mypsych.views.VerticalSeekBar
android:id="#+id/activityEvaluationEnergyValue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:max="10"
android:progress="0" />
</LinearLayout>
<TextView
android:id="#+id/TextView11"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.1"
android:gravity="center"
android:text="Energy"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.9"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/activityEvaluationWeatherValueDisplay"
android:layout_width="20dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<com.ulnda.mypsych.views.VerticalSeekBar
android:id="#+id/activityEvaluationWeatherValue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:max="10"
android:progress="0" />
</LinearLayout>
<TextView
android:id="#+id/TextView09"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.1"
android:gravity="center"
android:text="Weather"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.9"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/activityEvaluationHoursSleptValueDisplay"
android:layout_width="20dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<com.ulnda.mypsych.views.VerticalSeekBar
android:id="#+id/activityEvaluationHoursSleptValue"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:max="10"
android:progress="0" />
</LinearLayout>
<TextView
android:id="#+id/TextView07"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.1"
android:gravity="center"
android:text="Hours Slept"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
</TableLayout>
</LinearLayout>
Why RelativeLayout fill whole screen, not 0.6 ?
android:layout_weight makes sense only for LinearLayout. Lint should aware you about with a warning
RelativeLayout is the only one child who has layout_weight attribute so you should also specify weightSum:
<?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"
android:weightSum="1">
<RelativeLayout
android:background="#ff0000"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.6">
</RelativeLayout>
</LinearLayout>

Categories

Resources