The Below is my code i am not able to scroll the layout looking weird when i put scrollview
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context="willapp.stpl.com.willapp.util.ActivityPrintView">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="horizontal">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rootLayout">
<LinearLayout
android:id="#+id/table1heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select executer's relationship"
android:id="#+id/txtHeading"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:id="#+id/mainactivity_layoutName"
android:layout_below="#+id/table1heading"
android:layout_centerVertical="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mainactivity_txtLabelName"
android:text="Full Name:"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1">
</View>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mainactivity_txtValueName"
android:text="Sssdadaad"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/mainactivity_layoutLine1"
android:padding="5dp"
android:layout_below="#+id/mainactivity_layoutName"
android:layout_centerVertical="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mainactivity_txtLabelLine1"
android:text="Address Line1:"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1">
</View>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mainactivity_txtValueLine1"
android:text="Sssdadaad"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</FrameLayout>
Inside ScrollView try to use LinearLayout instead of RelativeLayout.
Something like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context="willapp.stpl.com.willapp.util.ActivityPrintView">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
// and here your main Relative layout
</LinearLayout>
</ScrollView>
</FrameLayout>
Related
this is my layout for a chat window in within my recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="418"
android:layout_width="0dp"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="100"
android:gravity="right"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/btn_profilepic_recview_chats"
android:background="#drawable/ripple"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="323"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="100"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="323"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="#drawable/chat_img_bubbletop"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#afebff">
<TextView
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textColor="#000000"
android:textSize="17sp"
android:id="#+id/txt_chatmessage_recview_chats"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="#drawable/chat_img_bubbletop"
android:rotation="180"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="100"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="323"
android:layout_height="match_parent">
<TextView
android:text="12.02.2012"
android:id="#+id/txt_date_recview_chats"
android:textSize="12sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_weight="216"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="10dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
The Background of the recyclerview is a simple image, that is supposed to show through the linear layouts. But unfortunately, this is the result:
So, as you can see, the background is displayed just right but the supposed to be transparent layout for the cardview i am using here is some wired black.
I can make it whatever color I want, but with:
android:background="#android:color/transparent"
it just gets black.
Can anyone help me here?
Thanks you! :)
You can use
app:cardBackgroundColor="#android:color/transparent"
You have to change your CardView background color. you can use
app:cardBackgroundColor="#android:color/transparent"
Instead of
android:background="#android:color/transparent"
Like :
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#android:color/transparent">
<!-- Your view design -->
</android.support.v7.widget.CardView>
... turns out CARDVIEWS do not have such attribute. Making the rootlayout a linearlayout solved this issue.
I'm trying to create a responsive layout using weights but I also need to use a scroll view in this case.
This is my code at this moment:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EncyclopediaFragment">
<!--Linear Container-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<!--Title Box-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:orientation="horizontal"
android:weightSum="100">
<!--Empty Space-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5">
</LinearLayout>
<!--Text Box-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="95">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/encyclopedia_mosntersLabel"
android:gravity="center"
android:textAlignment="viewStart"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40">
</LinearLayout>
</LinearLayout>
but it needs to be like this.
That layout is suppose to be responsive with weights but at the same time I need to make it possible to scroll.
So my question is: how can I create a layout responsive with weights and at the same time a layout that can scroll down, just like in the picture?
If you have a determined number of 6 Monsters and 8 Towers, here is how you should organize your layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Monsters"/>
<!-- the following LinearLayout should be repeated twice for 6 Monsters -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<MonsterView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<MonsterView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<MonsterView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
...
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Towers"/>
<!-- the following LinearLayout should be repeated twice for 6 Towers -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TowerView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TowerView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TowerView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
...
<!-- attention here for two Towers in the last row -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<TowerView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TowerView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
The content inside your ScrollView should use wrap_parent, and if you want to stretch the content inside it set android:fillViewport="true". Try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EncyclopediaFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Linear Container-->
</RelativeLayout>
</ScrollLayout>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EncyclopediaFragment">
<!--Toolbar-->
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Linear Container With Weights-->
</RelativeLayout>
</ScrollLayout>
</RelativeLayout>
When the application is launched layout is fine. But when the video is playing. the Layout of the button is moving up.
How to resolve this?
When the application is launched?
When the video is playing the button is moving upwards
Below I had placed the layoutfile.xml which i had been working on.
<?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:weightSum="1"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:background="#android:color/background_dark">
<ListView
android:id="#+id/VideoList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:foreground="#android:color/background_light" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1"
android:layout_weight="0.7">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:layout_gravity="center_vertical">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/videoView"
android:layout_gravity="center" />
</FrameLayout>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:text="New Button"
android:id="#+id/button"/>
</LinearLayout>
</LinearLayout>
You should make the LinearLayout(that contains FrameLayout and Button) height match_parent
No need for weight-sum, just make the layout_weights integers like 1 and 9 instead of 0.1 and 0.9
Also, fill_parent is deprecated, use match_parent instead.
You have a LinearLayout with single child. No need, just put ListView with same layout_params.
Lastly, your vertical LinearLayout on the right should have a height of match_parent.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal">
<ListView
android:id="#+id/VideoList"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#android:color/darker_gray"
android:foreground="#android:color/background_light" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="7">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:layout_gravity="center_vertical">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/videoView"
android:layout_gravity="center" />
</FrameLayout>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="New Button"
android:id="#+id/button"/>
</LinearLayout>
</LinearLayout>
Edit: Fixed layout Params on LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal">
<ListView
android:id="#+id/VideoList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#android:color/darker_gray"
android:foreground="#android:color/background_light" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="7">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:layout_gravity="center_vertical">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/videoView"
android:layout_gravity="center" />
</FrameLayout>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="New Button"
android:id="#+id/button"/>
</LinearLayout>
</LinearLayout>
I have done changes in listview "layout_width" and "layout_height" both should be match_parent ,Now it is working
I am newbie to android development and learning it to my own. I have a very strange problem of having strange space that comes in between every item of my recycler view. I have the following:
My recycler view is vertical with grid view layout of 2 spans(columns). What I have been trying is:
Code for Layout
<?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="wrap_content"
android:layout_marginLeft="#dimen/size_five"
android:layout_marginRight="#dimen/size_five"
android:layout_marginTop="#dimen/size_fifteen"
android:background="#color/blackColor"
android:clickable="true"
android:focusable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50">
<ImageView
android:id="#+id/album_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/blackColor"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/lowerline"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:background="#color/hotpinkColor"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/size_ten">
<TextView
android:id="#+id/album_title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="left"
android:text="Album Title"
android:textColor="#color/whiteColor"
android:textSize="#dimen/size_eight"
android:textStyle="bold"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/size_ten"
android:layout_weight="5"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/downloader"
android:layout_width="#dimen/size_thirty_six"
android:layout_height="#dimen/size_thirty_six"
android:layout_centerInParent="true"
android:src="#drawable/donwloaderimager"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/setteraswall"
android:layout_width="#dimen/size_fourty"
android:layout_height="#dimen/size_fourty"
android:layout_centerInParent="true"
android:src="#drawable/setteras"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Screen Shot
The Black space is showing the extra strange space that I want to remove.
Change:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50">
<ImageView
android:id="#+id/album_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/blackColor"
/>
</LinearLayout>
to
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50">
<ImageView
android:id="#+id/album_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/blackColor"
/>
</LinearLayout>
That is change the height of the second parent linear layout to wrap_content
I guess question is silly, but I am missing something in this and want to understand.
I am dividing the screen into two equal parts. I know this can be done by setting weight. But I do not know why I can not set weight in Linear layout. Instead I am setting weightSum, but what I understood about weightSum is, it is space on screen left after setting width and height I guess.
here is what I am doing
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:id="#+id/main_panel">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/top"
android:weightSum="100">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/list"
android:divider="#null"
android:dividerHeight="0dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/top"
android:weightSum="50"
android:layout_alignParentBottom="true"
android:id="#+id/ bottom">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/data"
android:orientation="vertical"
android:background="#D3D3D3"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<View
android:id="#+id/drag_line"
android:layout_width="50dp"
android:visibility="visible"
android:background="#drawable/bar"
android:layout_gravity="center_horizontal|top"
android:layout_height="170dp"
android:src="#drawable/line" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>
PS: I cannot set layout_weight property using android lollipop
Try with below code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:id="#+id/main_panel">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/top"
>
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/list"
android:divider="#null"
android:dividerHeight="0dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_below="#id/top"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:id="#+id/ bottom">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/data"
android:orientation="vertical"
android:background="#D3D3D3"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<View
android:id="#+id/drag_line"
android:layout_width="50dp"
android:visibility="visible"
android:background="#drawable/bar"
android:layout_gravity="center_horizontal|top"
android:layout_height="170dp"
android:src="#drawable/line" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/color_in_palette"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CCFFFF"
android:text="Button"
android:layout_weight="50"
android:textSize="0sp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50">
<TextView
android:id="#+id/color_id"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="(204,255,255)"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:numColumns="13"
android:layout_weight="48" >
</GridView>
</LinearLayout>
</LinearLayout>
In this button will occupy the half of the screen , and the other half is occupied by another Linear Layout , which contains a TextView & GridView
Problem:
You cant add a weightSum within a Relative layout that it is only bounded to linearlayout layout params itself.
solution:
add another linearlayout inside your relatie layout as a parent to both of the inner linear layout.
sample:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:id="#+id/main_panel">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/parent"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/top"
android:weightSum="0.5">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/list"
android:divider="#null"
android:dividerHeight="0dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/top"
android:weightSum="0.5"
android:layout_alignParentBottom="true"
android:id="#+id/ bottom">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/data"
android:orientation="vertical"
android:background="#D3D3D3"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<View
android:id="#+id/drag_line"
android:layout_width="50dp"
android:visibility="visible"
android:background="#drawable/bar"
android:layout_gravity="center_horizontal|top"
android:layout_height="170dp"
android:src="#drawable/line" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Weightsum is property used by parent to find the total weight sum by its children.This property is only applicable to LinearLayout. Its childrens should specify its weight with width or height as 0dp. You can find the tutorial here. So your layout.xml will be
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:weightSum="100" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="50"
android:divider="#null"
android:dividerHeight="0dp" />
<FrameLayout
android:id="#+id/data"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:background="#D3D3D3"
android:orientation="vertical" >
<View
android:id="#+id/drag_line"
android:layout_width="50dp"
android:layout_height="170dp"
android:layout_gravity="center_horizontal|top"
android:visibility="visible" />
</FrameLayout>
</LinearLayout>
Get Root attribute always be <Relative> and with in that write your remaining XML code.
e.g.
<?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="0dp"
android:layout_weight="1"
android:background="#color/black">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white">
</LinearLayout>
</LinearLayout>
//Replace above XML code by...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/black">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/white">
</LinearLayout>
</LinearLayout>
</RelativeLayout>