I have implemented a ViewFlipper with 8 child view in my application as follows.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#drawable/main_bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ViewFlipper
android:id="#+id/layout_tab_one"
android:layout_marginTop="70dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
layout="#layout/exterior_driverside_1"
/>
<include
layout="#layout/exterior_driverside_2"
/>
<include
layout="#layout/exterior_front_1"
/>
<include
layout="#layout/exterior_front_2"
/>
<include
layout="#layout/exterior_passenger_1"
/>
<include
layout="#layout/exterior_passenger_2"
/>
<include
layout="#layout/exterior_rear_1"
/>
<include
layout="#layout/interior_1"
/>
<include
layout="#layout/interior_2"
/>
<include
layout="#layout/interior_3"
/>
<include
layout="#layout/interior_4"
/>
<include
layout="#layout/interior_5"
/>
<include
layout="#layout/finalpage"
/>
</ViewFlipper>
</LinearLayout>
Each child layout resembles like this.
<LinearLayout 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/check_title"
android:layout_marginTop="10dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginRight="10dp"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="25dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Exterior / Rear "
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greytop_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
>
<TextView
android:id="#+id/tailights_txt"
android:textColor="#ffffff"
android:text="Tailights"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<CheckBox
android:id="#+id/tailights"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true" />
<EditText
android:id="#+id/tailights_edit"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/tailights"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greymid_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp" >
<TextView
android:id="#+id/bootlid_txt"
android:textColor="#ffffff"
android:text="Boot lid / Tailgate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"/>
<CheckBox
android:id="#+id/bootlid"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
<EditText
android:id="#+id/bootlid_edit"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/bootlid"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greymid_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp" >
<TextView
android:id="#+id/bumperbar_txt"
android:textColor="#ffffff"
android:text="Bumper Bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<CheckBox
android:id="#+id/bumperbar"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
<EditText
android:id="#+id/bumperbar_edit"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/bumperbar"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greymid_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp" >
<TextView
android:id="#+id/mudflaps_txt"
android:textColor="#ffffff"
android:text="Mud Flaps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<CheckBox
android:id="#+id/mudflaps"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
<EditText
android:id="#+id/mudflaps_edit"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/mudflaps"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greybott_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp" >
<TextView
android:id="#+id/rear_unapproved_txt3"
android:textColor="#ffffff"
android:text="Unapproved advertising"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<CheckBox
android:id="#+id/rear_unapproved3"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
<EditText
android:id="#+id/rear_unapproved_edit3"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/rear_unapproved3"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
</LinearLayout>
I have implemented onGestureListener(onFling) to switch over another child view of the ViewFlipper. If i put ScrollView for each child view, onFling is not working. But every child view needs a scrollview. How to implement ScrollView in the ViewFlipper ? It will be greatfull if someone suggests some code for me.
Hope this helps you
#Override
public boolean dispatchTouchEvent(MotionEvent ev){
super.dispatchTouchEvent(ev);
return productGestureDetector.onTouchEvent(ev);
}
Yes, this really works. Textview scrolls automatically when overflow is there, if you don't handle the swipe gesture of view flipper adapter. So when you handle the swipe gesture yourself, make your textview scrollable by a adding
mTextView.setMovementMethod(new ScrollingMovementMethod());
And add the dispatchtoucheventfunction shown above, in your Activity.
Related
I have an app where the scrolView (relative layout inside it) take up the whole screen (fill_parent). But instead of ending at the end of the phone i would like to have a fragment at the bottom and have the ScrollView layout to stop at the top of the fragment. I think it probably has to do with the height but can't really figure out the code. Please look at my imgur image to get my idea. Imgur_Image, press here
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"><![CDATA[
tools:context="c.timno.smsgsm.MainActivity">
]]>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="status?"
android:id="#+id/skicka"
android:hint="Status?"
android:layout_marginTop="38dp"
android:layout_below="#+id/buttonanvandare"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="på"
android:id="#+id/skickaaon"
android:layout_marginEnd="36dp"
android:layout_below="#+id/textViewlarm"
android:layout_alignEnd="#+id/skicka" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Av"
android:id="#+id/skickaaoff"
android:layout_below="#+id/textViewlarm"
android:layout_toEndOf="#+id/skickarela1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Relä 1"
android:id="#+id/skickarela1"
android:layout_alignTop="#+id/skickarela2"
android:layout_alignStart="#+id/skickaaon" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Relä 2"
android:id="#+id/skickarela2"
android:layout_below="#+id/textView"
android:layout_toEndOf="#+id/skickarela1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Aktivera"
android:gravity="center"
android:textSize="29dp"
android:id="#+id/textView"
android:layout_below="#+id/skickaaon"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Larm"
android:textSize="29dp"
android:id="#+id/textViewlarm"
android:layout_below="#+id/skicka"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Avaktivera"
android:textSize="29dp"
android:id="#+id/textView3"
android:autoText="false"
android:layout_below="#+id/textView"
android:layout_alignEnd="#+id/buttoninstallator"
android:layout_marginTop="46dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Relä 1"
android:id="#+id/skickatrela1off"
android:layout_below="#+id/textView3"
android:layout_toStartOf="#+id/skickatrela2off" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Relä 2"
android:id="#+id/skickatrela2off"
android:layout_alignTop="#+id/skickatrela1off"
android:layout_alignStart="#+id/skickarela2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Användare"
android:id="#+id/buttonanvandare"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/skickaaoff" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Installation"
android:id="#+id/buttoninstallator"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_toEndOf="#+id/buttonanvandare" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="status?"
android:id="#+id/statustxt"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="aon"
android:id="#+id/aon"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="aoff"
android:id="#+id/aoff"
android:layout_alignParentStart="true"
android:layout_below="#+id/statustxt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="on*1*"
android:id="#+id/rela1txxt"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="On*2*"
android:id="#+id/rela2onn"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="off*2*"
android:id="#+id/rela2offtxt"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="off*1*"
android:id="#+id/offrela1txt"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Värmestyrning"
android:textSize="33dp"
android:id="#+id/textView8"
android:layout_below="#+id/skickatrela1off"
android:layout_marginTop="25dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Komfortvärme"
android:textSize="29dp"
android:id="#+id/textView9"
android:layout_below="#+id/textView8" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heaton"
android:id="#+id/btnHeaton"
android:layout_below="#+id/textView9"
android:layout_alignEnd="#+id/skickatrela1off" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heatoff"
android:id="#+id/btnHeatoff"
android:layout_below="#+id/textView9"
android:layout_alignStart="#+id/skickatrela2off" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Underhållsvärme"
android:textSize="29dp"
android:id="#+id/textView10"
android:layout_below="#+id/btnHeaton"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Termon"
android:id="#+id/btnTermon"
android:layout_below="#+id/textView10"
android:layout_toStartOf="#+id/btnHeatoff" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Termoff"
android:id="#+id/btnTermoff"
android:layout_alignBottom="#+id/btnTermon"
android:layout_toEndOf="#+id/btnTermon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Heaton"
android:id="#+id/txtHeaton"
android:layout_alignTop="#+id/statustxt"
android:layout_alignEnd="#+id/statustxt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Heatoff"
android:id="#+id/txtHeatoff"
android:layout_alignBottom="#+id/statustxt"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Termon"
android:id="#+id/txtTermon"
android:layout_alignBaseline="#+id/aoff"
android:layout_alignBottom="#+id/aoff"
android:layout_alignEnd="#+id/statustxt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Termoff"
android:id="#+id/txtTermoff"
android:layout_alignTop="#+id/statustxt"
android:layout_alignEnd="#+id/txtHeatoff" />
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="c.timno.smsgsm20.SecondFragment"
android:id="#+id/fragmentsms"
android:layout_below="#+id/textView8"
android:layout_alignParentStart="true"
tools:layout="#layout/second_layout"
android:layout_above="#+id/textView10" />
</RelativeLayout>
</ScrollView>
I would suggest putting the ScrollView and the Fragment inside a new top-level element and then using the respective method within that element to adjust the size and position of each.
For instance, using a RelativeLayout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<ScrollView
android:id="#+id/scrollview"
android:layout_above="#+id/frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<RelativeLayout
android:paddingBottom="50dp"
...>
...
</RelativeLayout>
...
</ScrollView>
<Fragment
android:id="#+id/frag"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="50dp"
...>
...
</Fragment>
</RelativeLayout>
(Note that the padding on the bottom of the RelativeLayout inside the ScrollView matches the height of the Fragment so that contents of the ScrollView don't get hidden behind the Fragment)
You could also do this using LinearLayout as the parent element with an attribute of android:orientation="vertical", and the ScrollView and Fragment each getting an appropriate layout_weight attribute, but that's not as clean imho, so I'll leave it to you if you'd prefer to do that.
<ScrollView>
<RelativeLayout>
//main content
</RelativeLayout>
<FrameLayout android:alignParentBottom="true"/> load fragment here dynamically(or not)
</ScrollView>
This worked for me. Check this question out aswell
I tried to search this question but no1 has answerd this, so here it is.
i am using a list view inside a scroll view.
when i am adding an onitemcliked listener to the listview it is not responding.
how to i get the listview access? i mean how do i get which position has been clicked. i know how it is normally done but inside a scroll view the listview is not reponding.
this is the code of adding onitemcliked listner to lisview.
itemlist.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(cv, "position:"+arg2, Toast.LENGTH_SHORT).show();
}
});
here is the xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:id="#+id/et_agent_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Agent Details"
android:textSize="18dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:src="#drawable/linedivider" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Agent"
android:textStyle="italic" />
<TextView
android:id="#+id/login_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LoginId"
android:textSize="15dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="Route" />
<Spinner
android:id="#+id/route_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<requestFocus />
</Spinner>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="Shop" />
<TextView
android:id="#+id/tvShopName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_shopaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="Address : " />
<Button
android:id="#+id/button_no_order"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="No Order" />
</LinearLayout>
<TextView
android:id="#+id/et2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Details"
android:textSize="18dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:src="#drawable/linedivider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etSearchBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
</EditText>
<Button
android:id="#+id/btn_SearchProduct"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Search" />
</LinearLayout>
<TableLayout
android:id="#+id/displayOrderTableView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<Button
android:id="#+id/button_order"
style="?android:attr/buttonStyleSmall"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Order"
android:textAlignment="inherit" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:src="#drawable/underline" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="#+id/button_clear"
style="?android:attr/buttonStyleSmall"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Clear"
android:textAlignment="inherit" />
<Button
android:id="#+id/button_submit"
style="?android:attr/buttonStyleSmall"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Submit"
android:textAlignment="inherit" />
</LinearLayout>
</LinearLayout>
</ScrollView>
pleasde help me i am stuck on this.. it might be a very silly solution. but please help me
thank u in advance.
This is likely caused since that ScrollView is at higher level than the ListView in parent-child hierarchy. So that ScrollView can absorb touch events at its own level and does not pass them to its children. This results in the ListView will not get touch events at all and subsequently does not respond to onItemClicked.
The solution is here.
In order to view all the elements inside my relativelayout in smaller screens, I have made the choice to use a scrollview to make it possible (or at least to try to accomplish this). The problem: I'm unable to scroll. The result of having or not the scrollview is the same, if the screen is small some elements will get cut off (this was fine if scroll was possible). In some searches I have come across some scrollview with linearlayout implementations, but in my case I think it's not very good, because i need check boxes aligned to the right of text.
Heres the xml of what I got thus far:
<ScrollView
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:background="#231E1A"
android:keepScreenOn="true"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:ignore="ContentDescription"
android:fillViewport="true">
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_getDirections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="#string/btn_getDirections" />
<TextView
android:id="#+id/static_language"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/radioGroup"
android:layout_alignLeft="#+id/radioGroup"
android:text="#string/static_language"
android:paddingTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<AutoCompleteTextView
android:id="#+id/aComplete_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/static_language"
android:layout_alignLeft="#+id/static_language"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_destination" />
<TextView
android:id="#+id/static_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/aComplete_destination"
android:layout_alignLeft="#+id/aComplete_destination"
android:text="#string/static_destination"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/static_highways"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_destination"
android:layout_alignLeft="#+id/static_destination"
android:paddingBottom="10dp"
android:text="#string/static_highways"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="#+id/static_tolls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_highways"
android:layout_alignLeft="#+id/static_highways"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/static_tolls"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="#+id/static_useCurrentLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_tolls"
android:layout_alignLeft="#+id/static_tolls"
android:paddingTop="10dp"
android:text="#string/static_useCurrentLocation"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<AutoCompleteTextView
android:id="#+id/aComplete_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/static_useCurrentLocation"
android:layout_alignLeft="#+id/static_useCurrentLocation"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_origin" >
<requestFocus />
</AutoCompleteTextView>
<TextView
android:id="#+id/static_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/aComplete_origin"
android:layout_alignLeft="#+id/aComplete_origin"
android:text="#string/static_origin"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_origin"
android:layout_alignLeft="#+id/static_origin"
android:layout_alignParentTop="true"
android:paddingBottom="10dp"
android:scaleType="fitStart"
android:src="#drawable/logo" />
<CheckBox
android:id="#+id/tolls_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_tolls"
android:layout_alignBottom="#+id/static_tolls"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/highways_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_highways"
android:layout_alignBottom="#+id/static_highways"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/useLocation_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_useCurrentLocation"
android:layout_alignBottom="#+id/static_useCurrentLocation"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btn_getDirections"
android:layout_alignLeft="#+id/btn_getDirections"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#FFFFFF"
android:layout_marginRight="20dp"
android:text="#string/radio_english" />
<RadioButton
android:id="#+id/radio_portugues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="#string/radio_portugues" />
</RadioGroup>
</RelativeLayout>
</ScrollView>
Huzzah! I got it to work! It was all a combination, of linearlayout, scrollview and relativelayout were was needed. Now it scrolls perfectly when the screen its not big enough to view the full content. I'm guessing that changing to linearlayout, was in fact the key in this. Basically i applied what was stated in developer site: http://developer.android.com/reference/android/widget/ScrollView.html
A child that is often used is a LinearLayout in a vertical
orientation, presenting a vertical array of top-level items that the
user can scroll through.
The xml:
<ScrollView
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:background="#231E1A"
android:keepScreenOn="true"
android:scrollbars="none"
android:overScrollMode="never"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:ignore="ContentDescription"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:keepScreenOn="true"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/logo"
android:scaleType="fitStart"
android:src="#drawable/logo"/>
<TextView
android:id="#+id/static_origin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/static_origin"
android:paddingTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<AutoCompleteTextView
android:id="#+id/aComplete_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_origin" >
<requestFocus />
</AutoCompleteTextView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/static_useCurrentLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:paddingTop="10dp"
android:text="#string/static_useCurrentLocation" />
<TextView
android:id="#+id/static_tolls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/static_useCurrentLocation"
android:layout_below="#+id/static_useCurrentLocation"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/static_tolls" />
<TextView
android:id="#+id/static_highways"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/static_tolls"
android:layout_alignLeft="#+id/static_tolls"
android:paddingBottom="10dp"
android:text="#string/static_highways"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<CheckBox
android:id="#+id/tolls_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_tolls"
android:layout_alignBottom="#+id/static_tolls"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/highways_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_highways"
android:layout_alignBottom="#+id/static_highways"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/useLocation_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_useCurrentLocation"
android:layout_alignBottom="#+id/static_useCurrentLocation"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
</RelativeLayout>
<TextView
android:id="#+id/static_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/static_destination"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
<AutoCompleteTextView
android:id="#+id/aComplete_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_destination" />
<TextView
android:id="#+id/static_language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/static_language"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#FFFFFF"
android:layout_marginRight="20dp"
android:text="#string/radio_english" />
<RadioButton
android:id="#+id/radio_portugues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="#string/radio_portugues" />
</RadioGroup>
<Button
android:id="#+id/btn_getDirections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/btn_getDirections" />
</LinearLayout>
</ScrollView>
I have a custom list. I am trying to scroll horizontally only specific part. For Instance, in the below image iam trying to scroll horizontally just the orange box.
Here is my XML Layout: In the XML layout the Orange box starts "android:id="#+id/projected"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="63dp"
android:layout_marginLeft="0dp"
android:background="#drawable/bkg_img_fullcell"
android:orientation="horizontal" >
<!-- Left Column -->
<LinearLayout
android:id="#+id/widget_lineupview_playerdata_container"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:layout_toRightOf="#+id/sideView"
android:gravity="center_vertical"
android:layout_toLeftOf="#+id/projected"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4" >
<!-- rel 1 -->
<LinearLayout
android:id="#+id/playername1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_toRightOf="#+id/sideView">
<com.cbssports.nflapp.ffb.MyTextViewBold
android:id="#+id/widget_lineupview_playerdata_playername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:inputType="text|textNoSuggestions"
android:layout_marginLeft="5dp"
android:maxLines="1"
android:text=""
android:textColor="#08233e"
android:textSize="15dp" />
</LinearLayout>
<!-- rel 2 -->
<LinearLayout
android:id="#+id/widget_lineupview_playerdata_playerStatsIconContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toRightOf="#+id/playername1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/widget_lineupview_playerdata_statusIconSuspended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:src="#drawable/btn_s"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="#+id/sideView" >
<TextView
android:id="#+id/widget_lineupview_playerdata_playerPositionTeam"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:inputType="text|textNoSuggestions"
android:maxLines="1"
android:text=""
android:textColor="#333333"
android:textSize="12dp" />
<ImageView
android:id="#+id/widget_lineupview_playerdata_startingPitcherStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:src="#drawable/btn_baseballgraphic"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/sideView"
android:layout_width="#dimen/widget_lineup_table_status_column_width"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:layout_alignParentLeft="true"
android:background="#drawable/bkg_img_rosterpos"
android:gravity="center" >
<!-- <Button -->
<com.cbssports.nflapp.ffb.VerticalTextView
android:id="#+id/widget_lineupview_playerdata_playerStatusButton"
android:layout_width="21dp"
android:layout_height="60dp"
android:layout_margin="0dp"
android:padding="0dp"
android:textColor="#004a8e"
android:textSize="11dp"
android:textStyle="bold"
android:gravity="bottom|center" />
</LinearLayout>
***<LinearLayout
android:id="#+id/projected"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_toLeftOf="#+id/percentStarted">
<TextView
android:id="#+id/widget_lineupview_player_h2h_stats_started_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>
<LinearLayout
android:id="#+id/percentStarted"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_alignParentRight="true"
android:layout_marginLeft="2dp">
<TextView
android:id="#+id/widget_lineupview_player_projected_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>***
</RelativeLayout>
Thank You g00dy, i can able to solve it by adding one LinearLayout inside horizontalScrollView it.
Here is my solution.
<HorizontalScrollView
android:id="#+id/horizontalScroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:scrollbars="none">
<LinearLayout
android:id="#+id/horizontalScroll_linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentRight="true" >
<LinearLayout
android:id="#+id/projected"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_toLeftOf="#+id/percentStarted">
<TextView
android:id="#+id/widget_lineupview_player_h2h_stats_started_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>
<LinearLayout
android:id="#+id/percentStarted"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_alignParentRight="true"
android:layout_marginLeft="2dp">
<TextView
android:id="#+id/widget_lineupview_player_projected_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
You can also set the LinearLayout fillViewport to true and foregroundGravity to true (not sure if this last is necessary), and set the child LinearLayout gravity to right:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="#dimen/IconM"
android:id="#+id/account_food_scroll"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/client_add_button_layout"
android:foregroundGravity="right"
android:layout_marginLeft="#dimen/PadM"
android:fillViewport="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="#dimen/IconM"
android:id="#+id/account_food_layout"
android:gravity="right">
</LinearLayout>
</HorizontalScrollView>
I have designed an action sheet that appears when a user press a button. It is a separate xml file that I am including in another layout file. In the layout preview, it looks exactly as I want it. However, when it runs on my phone, the layout is messed up.
Here is how it should look:
And here is how it does look:
Does anyone have any idea why this might be happening?
Here is the layout code for the action sheet. The section that isn't displaying right is in the last linear layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/sheet_header" >
<ImageButton
android:id="#+id/left_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:layout_toLeftOf="#+id/center_justified"
android:background="#android:color/transparent"
android:src="#drawable/alignment_left" />
<ImageButton
android:id="#+id/center_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:background="#android:color/transparent"
android:src="#drawable/alignment_center" />
<ImageButton
android:id="#+id/right_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:layout_toRightOf="#+id/center_justified"
android:background="#android:color/transparent"
android:src="#drawable/alignment_right" />
<ImageButton
android:id="#+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:background="#android:color/transparent"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/center_justified"
android:layout_marginRight="10dp"
android:src="#drawable/sheet_done_btn"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/sheet_background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp" >
<TextView
android:id="#+id/font_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Font"
android:textColor="#806014"
android:textSize="20sp" />
<TextView
android:id="#+id/size_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Size"
android:textColor="#806014"
android:textSize="20sp" />
<TextView
android:id="#+id/color_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Color"
android:textColor="#806014"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
And here is how it is included:
<FrameLayout
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/edit_text_frame">
<include layout="#layout/edit_text"/>
</FrameLayout>
Edit: In addition to a fix for this specific problem does anyone know why the preview doesnt match the way it actually shows up on the phone?
Thanks for the help!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/sheet_header" >
<ImageButton
android:id="#+id/left_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:layout_toLeftOf="#+id/center_justified"
android:background="#android:color/transparent"
android:src="#drawable/alignment_left" />
<ImageButton
android:id="#+id/center_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:background="#android:color/transparent"
android:src="#drawable/alignment_center" />
<ImageButton
android:id="#+id/right_justified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:layout_toRightOf="#+id/center_justified"
android:background="#android:color/transparent"
android:src="#drawable/alignment_right" />
<ImageButton
android:id="#+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/center_justified"
android:background="#android:color/transparent"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/center_justified"
android:layout_marginRight="10dp"
android:src="#drawable/sheet_done_btn"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#drawable/sheet_background"
android:orientation="vertical" >
<TextView
android:id="#+id/font_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Font"
android:textColor="#806014"
android:textSize="20sp" />
<TextView
android:id="#+id/size_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Size"
android:textColor="#806014"
android:textSize="20sp" />
<TextView
android:id="#+id/color_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Color"
android:textColor="#806014"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
You could place the font, size, color TextViews into a Table Layout.