Android Linear Layout Split Screen with Scrollview - android

The following is my layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:layout_gravity="top"
android:background="#FFFFFF" >
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#ffffff"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#F4F2F2"
android:layout_weight="0.5"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:gravity="left"
android:text="Notes:"
android:layout_marginLeft="50sp"
android:layout_marginBottom="5sp"
android:textSize="15sp"
android:textColor="#000000" />
<EditText
android:id="#+id/notetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#000000"
android:layout_marginLeft="50sp"
android:layout_marginRight="50sp"
android:background="#ffffff">
</EditText>
<ImageView
android:id="#+id/mImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:src="#drawable/picframe" android:contentDescription="TODO"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:layout_weight="0.5"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</LinearLayout>
Basically I have 3 linear layouts
the first one is the size of the whole screen
the other two are inside the first and split the screen into two
the right hand layout displays a bitmap which works fine
The left hand layout displays a notes box
this all works fine but I want to make the left side scrollable so if you enter notes more than the height of the screen you can keep going and scroll down to see the rest
problem is it all works fine until I add the scrollview as above
the notes editbox and label disappear and cant be seen
If I remove the scrollview they come back
Any ideas where im going wrong?
As always any help appreciated
Mark

These are the changes you need to do in your xml
i.e. removing background color from scrollview and shifting linear layout background to scrollview and removing layout weight from linear layout and setting width as match_parent
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#F4F2F2"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="0.5"
android:baselineAligned="false"
android:background="#FFFFFF" >
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="0.5"
android:background="#ffffff"
android:fillViewport="true"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_weight="0.5"
android:background="#F4F2F2"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:layout_marginLeft="50sp"
android:layout_marginTop="10sp"
android:gravity="left"
android:text="Notes:"
android:textColor="#000000"
android:textSize="15sp" />
<EditText
android:id="#+id/notetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50sp"
android:layout_marginRight="50sp"
android:background="#ffffff"
android:ems="10"
android:textColor="#000000" >
</EditText>
<ImageView
android:id="#+id/mImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:contentDescription="TODO"
android:src="#drawable/image" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#FFFFFF"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</LinearLayout>

In you case equal weight is needed for child ScrollView and LinearLayout and set Scoll data to center of ScrollView :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" >
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4F2F2"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/textView2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Notes:"
android:textSize="15sp"
android:textColor="#000000"
android:layout_marginTop="5dp"/>
<EditText
android:id="#+id/notetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#000000"
android:background="#ffffff"
android:layout_marginTop="5dp">
</EditText>
<ImageView
android:id="#+id/mImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/picframe"
android:contentDescription="TODO"
android:layout_marginTop="5dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:layout_weight="1"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</FrameLayout>
</LinearLayout>
</LinearLayout>

Give this one a try, you don't need to give 0dp to your child LinearLayout.
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F2F2"
android:orientation="vertical" >

Related

Three children on RelativeLayout does not get place to be shown

I am trying to show four direct children on a Relative Layout where first one is a EdiText (in 'gone' visibility) and second one is LinearLayout with a TextView and ImageView and third is a ListView and fourth is another LinearLayout.
ListView gets over all children. I am posting below the code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollview"
android:background="#drawable/bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.antoinecampbell.gcmdemo.GcmActivity$PlaceholderFragment">
<EditText
android:id="#+id/recepient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="Number"
android:imeOptions="actionSend"
android:inputType="phone"
android:visibility="invisible">
<requestFocus />
</EditText>
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/recepient" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding_small"
android:text="Preview"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone"/>
<ImageView android:id="#+id/imageShow"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/abs__ic_go"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
</LinearLayout>
<ListView android:id="#+id/listMessages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayout1"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
/>
<LinearLayout
android:id="#+id/bottomview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_below="#+id/listMessages"
android:layout_alignParentBottom="true"
android:visibility="gone"
android:background="#FFFFFF">
<com.rockerhieu.emojicon.EmojiconEditText
android:id="#+id/name_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding_small"
android:layout_weight="1"
android:hint="#string/enter_message_text"
android:imeOptions="actionSend"
android:inputType="text"
android:layout_gravity="center_vertical"
android:visibility="visible"/>
<LinearLayout android:layout_width="wrap_content"
android:id="#+id/frameView"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<fragment
android:id="#+id/emojicons"
android:layout_width="match_parent"
android:layout_height="220dp"
class="com.rockerhieu.emojicon.EmojiconsFragment"/>
</LinearLayout>
<ImageButton
android:id="#+id/send_message_button"
android:background="#drawable/angry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:visibility="visible"/>
</LinearLayout>
</RelativeLayout>
Now I tried using LinearLayout with scrollview inside it, it's now not scrolling the listview
<?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" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/recepient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="Number"
android:imeOptions="actionSend"
android:inputType="phone"
android:visibility="invisible">
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding_small"
android:text="Preview"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone"/>
<ImageView android:id="#+id/imageShow"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/abs__ic_go"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
<ListView android:id="#+id/listMessages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayout1"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/bottomview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_below="#+id/listMessages"
android:layout_alignParentBottom="true"
android:visibility="visible"
android:background="#FFFFFF">
<com.rockerhieu.emojicon.EmojiconEditText
android:id="#+id/name_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding_small"
android:layout_weight="1"
android:hint="#string/enter_message_text"
android:imeOptions="actionSend"
android:inputType="text"
android:layout_gravity="center_vertical"
android:visibility="visible"/>
<LinearLayout android:layout_width="wrap_content"
android:id="#+id/frameView"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<fragment
android:id="#+id/emojicons"
android:layout_width="match_parent"
android:layout_height="220dp"
class="com.rockerhieu.emojicon.EmojiconsFragment"/>
</LinearLayout>
<ImageButton
android:id="#+id/send_message_button"
android:background="#drawable/angry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:visibility="visible"/>
</LinearLayout>
</LinearLayout>
The ListView will go over other elements because you've not given it any relative positions. In a relative layout, every element will be default appear at (0,0) (ie the top left corner of the view) unless it's given a layout_below, layout_alignBottom etc parameter to determine where it's drawn.
So in this case, you 'resumably want the ListView to have android:layout_below="#id/LinearLayout1 and the bottomview similarly android:layout_below="#id/listMessages.
Here is the xml as per your requirement.
<?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:layout_gravity="center"
android:gravity="center" >
<EditText
android:id="#+id/edNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="Number"
android:inputType="phone"
android:visibility="gone" />
<LinearLayout
android:id="#+id/llLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edNumber"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="linear layout text" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
</LinearLayout>
<ListView
android:id="#+id/lvList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/llBottom"
android:layout_below="#id/llLayout" >
</ListView>
<LinearLayout
android:id="#+id/llBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ababab"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Bottom Bar text" />
</LinearLayout>
</RelativeLayout>

ScrollView and Wrap_Content not work

I have a problem in my xml, the ScrollView does not work when my RelativeLayout is wrap_content, but if I have a larger screen than the fixed height works correctly, but if I have a larger fixed height than screen the works correctly, but I need to be wrap_content, because I have a listview that is populated gradually as client wants, follows the xml
<?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:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#fff">
</LinearLayout>
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="45"
android:fillViewport="true"
android:scrollbars="vertical">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="2dp"
android:background="#drawable/borda"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|center_horizontal"
android:id="#+id/lb_cabec"
android:text="#string/str_cabec" />
<TextView
android:id="#+id/lb_pessoa_status"
android:paddingTop="4dp"
android:paddingBottom="15dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textStyle="bold"
android:text="#string/pessoas_lb_mesa_cartao"
android:layout_below="#+id/lb_cabec"/>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="2dp"
android:background="#drawable/borda"
android:id="#+id/relative_prod"
android:layout_below="#+id/lb_pessoa_status">
<TextView
android:layout_width="fill_parent"
android:id="#+id/lb_prodMistAdd_cabec_prod"
android:layout_height="wrap_content"
android:background="#000"
android:textColor="#fff"
android:gravity="center_horizontal"
android:text="#string/prodMistAdd_str_prod" />
<ListView
android:id="#+id/mListProdMistAdd_prod"
android:layout_width="fill_parent"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content"
android:layout_below="#+id/lb_prodMistAdd_cabec_prod" />
<Button
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_below="#+id/mListProdMistAdd_prod"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:id="#+id/bt_prodMistAdd_addProd"
android:text="#string/prodMistAdd_bt_prod" />
</RelativeLayout>
<LinearLayout
android:layout_height="10dp"
android:layout_width="fill_parent"
android:id="#+id/lb_espaco_1"
android:layout_below="#+id/relative_prod"
android:orientation="vertical">
</LinearLayout>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="2dp"
android:background="#drawable/borda"
android:id="#+id/relative_quant"
android:layout_below="#+id/lb_espaco_1">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/lb_prodMistAdd_cabec_quant"
android:background="#000"
android:textColor="#fff"
android:gravity="center_horizontal"
android:text="#string/prodMistAdd_str_quant" />
<LinearLayout
android:layout_height="5dp"
android:id="#+id/tab_espaco_2"
android:layout_below="#+id/lb_prodMistAdd_cabec_quant"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#fff">
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/tab_espaco_2"
android:orientation="horizontal">
<EditText
android:id="#+id/tb_prodMistAdd_quantidade"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:editable="false"
android:gravity="center_vertical|right"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:layout_width="40dp"
android:layout_height="35dp"
android:gravity="center_horizontal"
android:id="#+id/bt_prodMistAdd_mais"
android:text="#string/prodMistAdd_bt_mais" />
<Button
android:layout_width="40dp"
android:layout_height="35dp"
android:gravity="center_horizontal"
android:id="#+id/bt_prodMistAdd_menos"
android:text="#string/prodMistAdd_bt_menos" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_height="10dp"
android:layout_width="fill_parent"
android:id="#+id/lb_espaco_2"
android:orientation="vertical"
android:layout_below="#+id/relative_quant">
</LinearLayout>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="2dp"
android:background="#drawable/borda"
android:id="#+id/relative_obs"
android:layout_below="#+id/lb_espaco_2">
<TextView
android:layout_width="fill_parent"
android:id="#+id/lb_prodMistAdd_cabec_obs"
android:layout_height="wrap_content"
android:background="#000"
android:textColor="#fff"
android:gravity="center_horizontal"
android:text="#string/prodMistAdd_str_obs" />
<LinearLayout
android:layout_height="5dp"
android:id="#+id/tab_espaco_3"
android:layout_below="#+id/lb_prodMistAdd_cabec_obs"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#fff">
</LinearLayout>
<ListView
android:id="#+id/mListProdMistAdd_obs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_below="#+id/tab_espaco_3" />
<Button
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_below="#+id/mListProdMistAdd_obs"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:id="#+id/bt_log_voltar"
android:text="#string/prodMistAdd_bt_obs" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
My listview are configured to not scroll, through code
try do define ScrollView layout_width and layout_height as match_parent, without layout_weight
by the way, you should not mix ScrollView with ListView since both have his own scroll. I suggest to split it like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
(...)
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>

Correct layout android

I am developing simple Android application. Here is the mockup of the layout I want to create (just to give you an idea).
On both sides there will be 4 pictures with words.
What would be the best way to do that? Here is what I have so far. Is that OK or is there any better way to do that?
<LinearLayout 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="#B36E106F"
android:orientation="horizontal"
android:baselineAligned="false"
tools:context=".AddRoute" >
<RelativeLayout
android:id="#+id/add_left_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_margin="5dp"
android:background="#0098FF" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_toRightOf="#+id/imageView1"
android:text="From" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_marginTop="48dp"
android:layout_toLeftOf="#+id/textView1"
android:src="#drawable/abc" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView2"
android:layout_marginTop="54dp"
android:src="#drawable/abc" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView3"
android:layout_marginTop="47dp"
android:src="#drawable/abc" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/add_right_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_margin="5dp"
android:background="#0098FF" >
</RelativeLayout>
</LinearLayout>
you will love this
<LinearLayout 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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/left"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:background="#drawable/abc_menu_dropdown_panel_holo_light">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:background="#drawable/abc_spinner_ab_focused_holo_dark">
</LinearLayout>
</LinearLayout>
I am using the layout_weight trick to make the left linearLayout and right linearlayout to be the same width.
what you need to do is modify the style, backgournd, margin and padding.
reading the google android docs won`t get you pregnant,so do more reading.
google design guide for linearLayout and layout_weight
i would do it like this
<LinearLayout 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="#B36E106F"
android:baselineAligned="false"
android:orientation="horizontal"
tools:context=".AddRoute" >
<LinearLayout
android:id="#+id/add_left_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="0.5"
android:background="#0098FF"
android:orientation="vertical" >
<!-- Images here -->
</LinearLayout>
<LinearLayout
android:id="#+id/add_right_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="0.5"
android:background="#0098FF"
android:orientation="vertical" >
<!-- Images here -->
</LinearLayout>
</LinearLayout>
LinearLayout is a lot faster than RelativeLayout, at least if you use relative layouts features like alignToRightOf and similar methods.
But as your not using any features, why using it at all?
besides that you should change your weight to 0.5 as you want them to split the space equally. 100% => 1 except if you set a different weightSum
Since the number of the pictures on the both sides are determined. You can use a Horizontal LinearLayout with two Vertical LinearLayout inside it. And use the layout_weight attribute to let them split the parent layout equally. Like this:
<?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="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
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" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
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" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
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" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
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" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
Put your image and textView in the 8 horizontalLinearLayout.
Then if the number of images is determined during the runtime, you can try staggereGridView.

Android - How to make button to swap fullscreen mode and current size video

I have some question for my videos player project.I try to make button to swap video size from current size to full screen mode and I want to add this to my media controller too.My project has only landscape screen.Please help me to solve this problem. :(
Here is my application design.
And here's my xml file.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical"
tools:context=".MoviePlayerActivity" >
<LinearLayout
android:id="#+id/HeadPanel"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:gravity="left" >
<ImageButton
android:id="#+id/btnBack"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:src="#drawable/img_back" />
<ImageButton
android:id="#+id/btnBrightness"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:src="#drawable/img_brightness" />
</LinearLayout>
<TextView
android:id="#+id/txtHeadTitle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginRight="5sp"
android:layout_weight="3"
android:gravity="right"
android:text="#string/movie_title"
android:textColor="#FFFFFF"
android:textSize="#dimen/xhead"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/ContentPanel"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/VideoPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<VideoView
android:id="#+id/vdoMovie"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/VideoDetail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5sp"
android:layout_weight="5"
android:background="#drawable/blue_corner"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtMovieTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="#dimen/body" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_bg"
android:choiceMode="singleChoice"
android:divider="#242424"
android:dividerHeight="2dp"
android:listSelector="#drawable/list_bg_select" >
</ListView>
</LinearLayout>
</LinearLayout>
Sorry for my language skill.Thanks :)

android layout with automatic scrollview

i have in my android main.xml file as the following..
when i run it is showing some exception but in main.xml in graphical view it is not showing any error..
follwing is my code inside Linearlayout
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="UserName"/>
<EditText android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""/>
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="login"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=""/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""/>
<Button
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn"/>
</LinearLayout>
</ScrollView>
ScrollView should have ONLY ONE child.
ScrollView should have ONLY ONE child. in ur example u have placed 2 linear layouts inside scrollview which is causing error..
place the 2 linear layouts inside 1 linear layout and place the whole thing in scrollview. it will work..
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/UserNameText"/>
<EditText
android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/UserNameText"/>
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/UserNameText"/>
<EditText
android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/UserNameText"/>
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
ScrollViews can only contain a single child view. Wrap your two LinearLayouts in another LinearLayout.
You also have both linear layouts height set to match_parent. This won't work in a scrollview. They should both be set to wrap_content
try this xml for your problem
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="UserName"/>
<EditText android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""/>
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="login"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=""/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""/>
<Button
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Thanks for more detail click this link Can we use a ScrollView inside a LinearLayout?
Scroll View can have only One Direct child..
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="UserName" />
<EditText
android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="login" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
<Button
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn" />
</LinearLayout>
</LinearLayout> </ScrollView>
ScrollView should have only one child.

Categories

Resources