in android i have add two list view and add in linear layout this linear layout add in scroll but when i scroll on listview whole layout scrollable how we can scroll specific view my xml is below
android:layout_below="#+id/pvr_add">
<LinearLayout android:id="#+id/linear"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:id="#+id/lineshow" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:src="#drawable/largeline"
android:layout_marginTop="3dip"
android:layout_centerHorizontal="true">
</ImageView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/theater_details" android:layout_width="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_height="50dip">
<ImageView android:id="#+id/line" android:src="#drawable/line"
android:layout_below="#+id/lineshow"
android:layout_centerInParent="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lineshow"
android:layout_centerInParent="true"
android:layout_toLeftOf="#+id/line"
android:paddingLeft="8dip"
android:id="#+id/movie_name" android:text="English(UA)" />
<TextView android:layout_width="wrap_content"
android:gravity="right" android:layout_height="wrap_content"
android:paddingRight="8dip"
android:layout_below="#+id/lineshow"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/line"
android:textColor="#f8c400"
android:layout_centerInParent="true"
android:id="#+id/theater_location" />
</RelativeLayout>
<ImageView android:id="#+id/lineshow" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:src="#drawable/largeline"
android:layout_marginTop="3dip"
android:layout_centerHorizontal="true">
</ImageView>
<TextView android:layout_width="fill_parent"
android:layout_gravity="center_horizontal" android:layout_height="wrap_content"
android:layout_below="#+id/theater_details" android:id="#+id/select_date_time"
android:layout_marginLeft="10dip"
android:layout_marginTop="5dip"
android:text="Select date and time" />
<TableLayout android:id="#+id/weekly_show"
android:layout_below="#+id/select_date_time"
android:layout_width="270dip" android:layout_marginTop="10dip"
android:background="#drawable/gap"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal" android:stretchColumns="*"
android:layout_height="wrap_content">
</TableLayout>
<ListView android:layout_height="100dip"
android:cacheColorHint="#00000000" android:layout_gravity="center_horizontal"
android:listSelector="#drawable/list_selector_background"
android:choiceMode="multipleChoice"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="270dip" android:layout_below="#+id/weekly_show"
android:id="#android:id/list"></ListView>
<LinearLayout android:id="#+id/linear"
android:orientation="vertical" android:paddingTop="15dip"
android:layout_below="#android:id/list" android:layout_gravity="center_horizontal"
android:layout_width="270dip" android:layout_height="wrap_content">
<RelativeLayout android:layout_width="270dip"
android:layout_height="30dip" android:id="#+id/reserve_seat"
android:visibility="visible"
android:background="#drawable/roundedcorner">
<TextView android:layout_width="wrap_content"
android:layout_alignParentLeft="true" android:layout_height="wrap_content"
android:textSize="12dip"
android:layout_marginLeft="3dip"
android:id="#+id/seat_reqired" android:text="How many seat would you like"
android:textColor="#000000"
/>
<TextView android:layout_width="wrap_content"
android:layout_alignParentRight="true" android:layout_height="fill_parent"
android:gravity="center"
android:id="#+id/seekbarvalue" android:background="#drawable/noofseats" />
</RelativeLayout>
<SeekBar android:layout_width="270dip"
android:visibility="visible"
android:layout_height="wrap_content" android:layout_below="#+id/reserve_seat"
android:paddingTop="10dip" android:id="#+id/seekbar" android:max="10" />
<RelativeLayout android:layout_width="270dip"
android:layout_height="100dip" android:id="#+id/check_avilable_seat"
android:visibility="gone"
android:layout_marginTop="10dip" >
<ListView android:layout_height="100dip"
android:cacheColorHint="#00000000" android:layout_gravity="center_horizontal"
android:listSelector="#drawable/list_selector_background"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="270dip"
android:background="#drawable/roundedcorner"
android:id="#+id/list1"></ListView>
</RelativeLayout>
<Button
android:id="#+id/proceed"
android:layout_gravity="center_horizontal"
android:background="#drawable/proceed_button"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:visibility="gone"
android:layout_width="wrap_content" android:layout_height="30dip"></Button>
</LinearLayout>
</LinearLayout>
</ScrollView>
You missed the opening scrollview part of the tag...
However this question is identical to
Android ScrollView layout problem
In short: never put listview inside scrollview.
Related
I'm trying to create the following display, where the text scrolls and the other elements are fixed to the bottom of the screen:
However, it is appearing as follows, where the text doesn't scroll and it's pushing the elements off the screen.:
This is the layout I'm using:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ScrollView
android:id="#+id/scroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtTC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingLeft="20dp"
android:layout_alignParentLeft="true" />
</ScrollView>
<CheckBox
android:id="#+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center"
android:text="Don't Show Again"
android:layout_below="#+id/scroller" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/chkBox"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1">
<ImageButton
android:id="#+id/imgCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="0dip"
android:src="#drawable/stop"
android:paddingBottom="5dip"
android:paddingRight="5dip"
android:background="#drawable/common_button" />
<TextView
android:id="#+id/txtCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_below="#id/imgCancel"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="OK"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
What do I need to do to make the text scroll and the other elements fixed to the bottom of the screen?
Try replacing this xml code and apply images where you need
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#5555"
android:gravity="center"
android:orientation="vertical"
android:padding="25dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Terms and Conditions"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ScrollView
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView
android:id="#+id/txtTC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="20dp"
android:textSize="20sp" />
</ScrollView>
<CheckBox
android:id="#+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/scroller"
android:layout_gravity="center_vertical"
android:text="Don't Show Again" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/chkBox"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1">
<ImageButton
android:id="#+id/imgCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="0dip"
android:paddingBottom="5dip"
android:paddingRight="5dip" />
<TextView
android:id="#+id/txtCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_below="#id/imgCancel"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="OK"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
You should add the ScrollView Containing the TextView inside a Layout(Linear would do). I hope it helps
i have activity that display some info about school, and subscribe button
when the subscribe button is pressed, it shows another layout with edittext and button to enter subscription code
no the problem, if i pressed cancel the i got black background in the middle
this is the activity layout code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollingCache="false"
android:cacheColorHint="#00000000"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:id="#+id/linearLayout"
android:scrollingCache="false"
android:cacheColorHint="#00000000"
android:background="#333"
android:layout_marginBottom="10dp"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/followOrgImage"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="5"
android:paddingLeft="7dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Untitled!"
android:id="#+id/titleTxt"
android:textStyle="bold"
android:textColor="#fff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""
android:id="#+id/followTextDate"
android:textColor="#8B8B8B" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""
android:id="#+id/followTextDesc"
android:textColor="#C4C4C4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:id="#+id/followTextCountry"
android:textColor="#fafafa" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="250dp"
android:layout_height="45dp"
>
<Button
android:layout_width="125dp"
android:layout_height="fill_parent"
android:text="#string/follow"
android:id="#+id/follow_btn"
android:clickable="false"
android:layout_marginTop="5dp"
android:textColor="#ddd" />
<Button
android:layout_width="125dp"
android:layout_height="fill_parent"
android:text="#string/subscribe"
android:id="#+id/subscribe_btn"
android:clickable="false"
android:layout_marginTop="5dp"
android:textColor="#ddd" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:scrollingCache="false"
android:cacheColorHint="#00000000"
android:visibility="gone"
android:id="#+id/subscribe_layout"
>
<EditText
android:layout_width="186dp"
android:layout_height="wrap_content"
android:id="#+id/subscribe_edit_txt"
android:layout_marginTop="3dp"
android:textColor="#fafafa"
android:singleLine="true"
android:textCursorDrawable="#drawable/cursor_color"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:hint="#string/profiles_code_hint" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/addBtn"
android:id="#+id/subscribe_add_btn"
android:clickable="false"
android:layout_marginTop="5dp"
android:textColor="#ddd" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="5dp"
android:scrollingCache="false"
android:cacheColorHint="#00000000"
android:id="#+id/linearLayout2"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/organization_type"
android:id="#+id/textView"
android:textSize="15sp"
android:textStyle="bold" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#B1B1B1"
android:layout_marginTop="4dp"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout2"
android:id="#+id/linearLayout3"
android:paddingLeft="20dp"
android:paddingTop="5dp"
android:paddingRight="20dp"
android:paddingBottom="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:textColor="#444"
android:textSize="13sp"
android:id="#+id/typeTxt"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout3"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="5dp"
android:id="#+id/linearLayout4"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/address"
android:id="#+id/textView2"
android:textSize="15sp"
android:enabled="true"
android:textStyle="bold" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#B1B1B1"
android:layout_marginTop="4dp"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout4"
android:paddingLeft="20dp"
android:paddingTop="5dp"
android:paddingRight="20dp"
android:paddingBottom="15dp"
android:id="#+id/linearLayout5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:textColor="#444"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/addressTxt"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout5"
android:visibility="gone">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/hdnBtn"
android:visibility="gone"/>
</LinearLayout>
</RelativeLayout>
i tried to give some layouts this attributes
android:scrollingCache="false"
android:cacheColorHint="#00000000"
but it didn't solve it
any suggestions?
By seeing your requirement, There is no need of the extra tags that you have used like cacheColorHint.
Simply, show the first screen, then navigate the user to new screen on subscribe button click.
You need 2 different xml layouts for it.
Or 2nd approach could be, On click of Subscribe button, set visibility of old elements to gone and set visibility of new required elements to visible.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/quickaction_shadow_horiz"
android:paddingRight="#dimen/quickaction_shadow_horiz">
<FrameLayout
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip">
<LinearLayout
android:id="#+id/quickaction_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/quickaction_top_frame"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/quickaction_icon"
android:layout_width="54dip"
android:layout_height="57dip"
android:layout_marginLeft="15dip"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:scaleType="center"
android:visibility="gone" />
<LinearLayout
android:id="#+id/quickaction_header_content"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="#+id/quickaction_primary_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:ellipsize="marquee"
android:textColor="#android:color/primary_text_light"
android:textStyle="bold"
android:textSize="18dip"
android:visibility="gone" />
<TextView
android:id="#+id/quickaction_secondary_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/secondary_text_light"
android:textSize="15dip"
android:layout_marginTop="-3dip"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<HorizontalScrollView
android:id="#+id/scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fadingEdgeLength="0dip"
android:background="#drawable/quickaction_slider_background"
android:scrollbars="none">
<LinearLayout
android:id="#+id/quickaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dip"
android:paddingBottom="4dip"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/quickaction_slider_grip_left" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/quickaction_slider_grip_right" />
</LinearLayout>
</HorizontalScrollView>
<FrameLayout
android:id="#+id/footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/scroll"
android:background="#drawable/quickaction_bottom_frame" />
<!-- <LinearLayout
android:id="#+id/footer_disambig"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scroll"
android:background="#drawable/quickaction_disambig_bottom_bg"
android:orientation="vertical"
android:visibility="gone">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#color/quickaction_disambig"
android:divider="#drawable/quickaction_disambig_divider"
android:cacheColorHint="#null" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="19dip"
android:layout_marginRight="19dip"
android:minHeight="60dip"
android:textColor="#f000"
android:textStyle="bold"
android:text="Remember Choice"
android:textAppearance="?android:attr/textAppearanceSmallInverse"
android:button="#drawable/quickaction_disambig_checkbox" />
</LinearLayout> -->
<ImageView
android:id="#+id/arrow_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/quickaction_arrow_up" />
<ImageView
android:id="#+id/arrow_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-1dip"
android:layout_below="#id/footer"
android:src="#drawable/quickaction_arrow_down" />
<!-- <ImageView
android:id="#+id/arrow_down_stub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-1dip"
android:layout_below="#id/footer_disambig"
android:visibility="invisible"
android:src="#drawable/quickaction_arrow_down" />-->
</RelativeLayout>
Hello i want my Framelayout to be of same width as of the Horizontalscrollview i does not take the width of the Horizontalscrollview just stays there at the start postion if given wrap_content but takes the fill_parent i want to keep wrap_content how can i do that?
Add below two lines inside <HorizontalScrollView> and give it a try:
android:layout_alignLeft="#id/header"
android:layout_alignRight="#id/header"
hope this helps.
I am trying to build a complex listview item layout with all of the elements being the same dimensions for each listview item with the entire layout taking up the whole width of the screen. So far I have attempted doing this using a linearlayout and found that this is the wrong approach. I have then attempted using a relative layout however this has not worked for me so I hope that someone can point out how I can make this work.
Here is a diagram of what I am trying to build.
Here is some more details about the diagram:
Only elements 5 and 6 have the same content for every list item. The
rest of elements all will have different text however the layout
should always be the same size.
Element 4 should only be 2 lines. Elements 1, 2 and 3 should only be 1
line.
Element 2 should be aligned left and element 3 should be aligned
right.
Element 2 and 3 should each be half of the width of element 4.
Here is my attempt at this layout using a RelativeLayout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="2dp">
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="20dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" />
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toRightOf="#id/txtRaceNumber"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:ellipsize="marquee"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toRightOf="#id/txtRaceNumber" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txtRaceClass" />
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:paddingRight="8dip"
android:focusable="false"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txtRaceStartTime" />
<ImageView
android:src="#drawable/go"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/btnTracklist" />
</RelativeLayout>
Using this RelativeLayout all of the elements appear scrambled within the layout.
How can I get all of these elements to align as I have shown in the Diagram?
Is this what you need?
<LinearLayout
android:id="#+id/lin1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:text="TExt1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/lin1"
android:layout_toLeftOf="#+id/lin3">
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text4"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="text2"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="text3"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/lin3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:focusable="false"
android:paddingRight="8dip" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:src="#drawable/ic_launcher" />
</LinearLayout>
try this code
<?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="90dp"
android:gravity="center|left"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left|center"
android:layout_gravity="center"
android:gravity="center"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<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:gravity="center"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left|center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
<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:gravity="left|center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
<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:gravity="left|center" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="3dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="3dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
</LinearLayout>
I have managed to get the desired layout using weightSum on the main layout.
Here is the code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/twolinechecked"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:maxHeight="?android:attr/listPreferredItemHeight"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:orientation="horizontal"
android:weightSum="1"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="40dip"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_gravity="center"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="6dip">
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/linearTextInner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal">
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:ellipsize="marquee"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:maxLines="1"
android:layout_alignParentRight="true"
android:gravity="right" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:layout_marginLeft="5dip"
android:paddingRight="8dip"
android:layout_gravity="center_vertical|center_horizontal" />
<ImageView
android:src="#drawable/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_alignParentRight="true" />
</LinearLayout>
Follow below structure I feel you can achieve what you want use weight and weightSum.
<LinearLayout orientation="horizontal">
<LinearLayout>
<TextView/>
</LinearLayout>
<LinearLayout orientation="vertical">
<TextView/>
<LinearLayout orientation="horizontal">
<TextView/>
<TextView/>
</LinearLayout>
<ImageButton/>
<ImageView/>
</LinearLayout>
EDIT
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="2dp"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.2" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.7"
android:gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.3"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center" />
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15" />
<ImageButton
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15" />
</LinearLayout>
I have a WebView at the bottom of view in ViewPager... When I slide through the items of ViewPager. The View moves on down. (I guess the focus goes to webview)
I am not sure whether this is due to WebView.
Loading the webview with html data using
webView.loadDataWithBaseURL(null, data, "text/html","utf-8",null);
It's annoying when the page moves down every time the next item is loaded. I have an ImageView at the top of the View
Any pointers?
here is the xml:
<ScrollView
android:id="#+id/scroll_view_1"
style="#style/some_style"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none" >
<LinearLayout
android:id="#+id/linear_layout_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/some_drawable"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relative_layout_1"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:paddingLeft="5dip"
android:paddingRight="5dip" >
<LinearLayout
android:id="#+id/linear_layout_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dip"
android:gravity="center" >
<PageIndicator
android:id="#+id/page_indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relative_layout_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:visibility="visible" >
<TextView
android:id="#+id/text_view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:text="1/50"
android:textColor="#000000"
android:textSize="16sp" />
<ImageView
android:id="#+id/image_view_1"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_marginRight="5dip"
android:layout_toLeftOf="#id/text_view_1"
android:scaleType="centerInside"
android:src="#drawable/some_drawable_3" />
<ImageView
android:id="#+id/image_view_2"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_marginRight="5dip"
android:layout_toLeftOf="#id/image_view_1"
android:scaleType="centerInside"
android:src="#drawable/some_drawable_4" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="relative_layout_3"
android:layout_height="wrap_content"
android:background="#f8f8f8"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="5dip"
android:paddingTop="5dip" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/some_drawbale_2" />
<TextView
android:id="#+id/text_view_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="6dip"
android:gravity="left|center_vertical"
android:paddingLeft="3dip"
android:paddingRight="7dip"
android:text="$121.00"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<Button
android:id="#+id/button_1"
android:layout_width="95dip"
android:layout_height="30dip"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15sp"
android:background="#drawable/some_drawable_5"
android:gravity="center"
android:textSize="15dip" />
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/text_view_3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:gravity="left"
android:lineSpacingExtra="2dip"
android:text="Some Text"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingTop="15dip" >
<WebView
android:id="#+id/web_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
I had the same kind of issue. And adding this attribute to the top most linear layout solved the issue. try this,
android:descendantFocusability="blocksDescendants".
In your case add this to your Linear Layout inside the ScrollView and check.