i have a fragment with a RelativLayout that holds a TextView at the top, a LinearLayout (which is filled dynammically with CheckBoxes) in the middle and a Button at the bottom.
The problem is that i need scrolling if too many CheckBoxes are added. The Button is alligned using the attribut layout_alignParentBottom and is displayed at the top of the screen. This attribut is not working with Scrollview.
<?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:orientation="vertical">
<TextView
android:id="#+id/show_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="25sp"
android:gravity="center"
android:padding="10dp" />
<LinearLayout
android:id="#+id/hold_check_boxes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="#+id/show_content" />
<Button android:id="#+id/save"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="#string/save"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
any suggestions?
EDIT: with ScrollView
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/topLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/show_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="25sp"
android:gravity="center"
android:padding="10dp"
android:background="#drawable/bottom_border" />
<LinearLayout
android:id="#+id/hold_check_boxes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="#+id/show_content" />
<Button android:id="#+id/save"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="#string/save"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
You can do like this without taking as parent. The only thing you have to do is take Linearlayout in ScrollView.
<?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" >
<TextView
android:id="#+id/show_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:textColor="#color/black"
android:textSize="25sp" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/save"
android:layout_below="#+id/show_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<LinearLayout
android:id="#+id/hold_check_boxes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<Button
android:id="#+id/save"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/save" />
</RelativeLayout>
Update:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/show_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:textColor="#color/black"
android:textSize="25sp" />
<LinearLayout
android:id="#+id/hold_check_boxes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/show_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" />
<Button
android:id="#+id/save"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/hold_check_boxes"
android:layout_centerHorizontal="true"
android:text="#string/save" />
</RelativeLayout>
</ScrollView>
Related
I am working on a concept to make gridview and listview in a same activity and want to make whole screen scrollable.
My concept is :
I have created a listview A as main listview and adding gridview g and another listview l as header and footer of main listview A but this is not making the whole screen scrollable.
Here is my main xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/shopping_list_bg"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativelayout2"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="#drawable/dark_pink_header"
android:gravity="center_vertical" >
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#drawable/back_but" />
<Button
android:id="#+id/devicder_button"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/back_button"
android:background="#drawable/divider" />
<Button
android:id="#+id/sample_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/devicder_button"
android:background="#drawable/menu_icon" />
<RelativeLayout
android:id="#+id/mid_header_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/fav_button"
android:layout_toRightOf="#+id/sample_button"
android:gravity="center" >
<ImageView
android:id="#+id/logoIMg"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="#drawable/store_guide_logo" />
<TextView
android:id="#+id/header_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/logoIMg"
android:gravity="center"
android:text="#string/e_couponing"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<CheckBox
android:id="#+id/fav_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:button="#drawable/custom_favorite_checkbox"
android:visibility="invisible" />
</RelativeLayout>
<ListView
android:id="#+id/estickermainListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativelayout2"
android:layout_marginTop="3dp"
android:cacheColorHint="#android:color/transparent"
android:scrollbars="none" >
</ListView>
</RelativeLayout>
Footer xml:
<?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:background="#android:color/black"
android:orientation="vertical" >
<ListView
android:id="#+id/estickertListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="3dp"
android:cacheColorHint="#android:color/transparent"
android:scrollbars="none" >
</ListView>
</LinearLayout>
Header xml 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:background="#android:color/white"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/header_rl"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#drawable/gray_bg"
android:gravity="center_vertical" >
<TextView
android:id="#+id/esticker_txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/e_stickers_list"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<GridView
android:id="#+id/e_sticker_gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="3" >
</GridView>
<RelativeLayout
android:id="#+id/quantiy_product_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="#drawable/shopping_list_top"
android:orientation="horizontal" >
<TextView
android:id="#+id/coupon_bonanza_Txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/coupon_bonanza"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
I'm trying to emulate a dock for a launcher with 3 text views evenly spaced out across said dock... For some reason I can't get my text views to center align with in there parent linear layouts, can someone please explain to me what is my issue here?
Here is my layout in XML:
<?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/main_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF" >
<LinearLayout
android:id="#+id/footer"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99000000"
android:paddingBottom="20dp"
android:paddingTop="20dp" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/launcher_footer_icon"
android:gravity="center"
android:text="Internet Browser"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/launcher_footer_icon"
android:gravity="center"
android:text="Flight Tracker"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/launcher_footer_icon"
android:gravity="center"
android:text="Airline Info"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Try this out, I think you have too many inner layouts.. you can use layout_weight to achieve this.
<?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/main_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/blue"
android:orientation="horizontal"
android:padding="20dp"
android:weightSum="15.0" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5.0" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:gravity="center"
android:text="Internet Browser"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5.0" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:gravity="center"
android:text="Flight Tracker"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5.0" >
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:background="#color/blue"
android:gravity="center"
android:text="Airline Info"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
I need set textView10 at center of vertical and horizontal. I've tried a lot without results... I tried with gravity options but nothing.. any idea? textView10 is within scrollview. Thanks for help.
<?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="#000000"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="151dp"
android:layout_height="fill_parent"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="13sp"
android:textStyle="italic" />
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />
</LinearLayout>
<?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="#000000"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="151dp"
android:layout_height="fill_parent"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="320dp"
android:background="#000000"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="13sp"
android:text="Hi What is your name"
android:textStyle="italic" />
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />
Change your outer layout to RelativeLayout and position yout ScrollView at the parent center. Position other elements in relation to one in center
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:id="#+id/TextView1"
android:layout_width="151dp"
android:layout_height="fill_parent"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="13sp"
android:textStyle="italic" />
</ScrollView>
</RelativeLayout>
Put the TextView inside of a RelativeLayout, and put that RelativeLayout inside of the ScrollView.
Then, set android:layout_centerInParent="true" within the TextView
How to make spinner to fill empty place in left side?
android:layout_width="fill_parent" does not help.
XML layout:
<Spinner
android:id="#+id/spn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text1" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text2" />
</LinearLayout>
I would make use of a Relative Layout and Linear Layout combination to achieve this,
<?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" >
<Spinner
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/lin_layout" />
<LinearLayout
android:id="#+id/lin_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asd" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fgdas" />
</LinearLayout>
</RelativeLayout>
The Output,
Andro solution's above is perfect as per your need .....
but if data in text view is dynamic and may be too long then can try android:weightSum="1" here
<?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"
>
<Spinner
android:id="#+id/spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".8" />
<LinearLayout
android:id="#+id/lin_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight=".2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text2" />
</LinearLayout>
</LinearLayout>
I want to place a textview on the right of a layout and on the left of a layout, but they keep stacking ontop of each other:
<LinearLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent" android:orientation="horizontal">
<TextView
android:id="#+id/lefttext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:text="Symbol"/>
<TextView
android:id="#+id/righttext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:text="Price"/>
</LinearLayout>
Try this:
<?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"
>
<TextView
android:id="#+id/left_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Symbol"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Price"
/>
</LinearLayout>
Why are you specifying 0dip for the height on these?
For symbols on sides:
<?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"
>
<TextView
android:id="#+id/left_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dip"
android:gravity="left"
android:text="Symbol"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dip"
android:gravity="right"
android:text="Price"
/>
</LinearLayout>
And done with a RelativeLayout:
<?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"
>
<TextView
android:id="#+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:layout_alignParentLeft="true"
android:text="Code"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:layout_toRightOf="#+id/left_text"
android:gravity="right"
android:text="Company Name"
/>
</RelativeLayout>
With LinearLayout, just put an empty TextView with the weight between them:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/lefttext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Symbol"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:id="#+id/righttext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Price"/>
</LinearLayout>
Use android:layout_alignParentLeft="true" and android:layout_alignParentRight="true" on view inside RelaytiveLayout like this
<?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="wrap_content"
>
<TextView
android:id="#+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left|center_vertical"
android:text="Symbol"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right|center_vertical"
android:text="Price"
/>
</RelativeLayout>
Alternatively you can use TableLayout with stretchColumn set to stretch the second column to the size of parent.