How to make Horizontal view scroller for Android Widget? - android

Basically, I am making an android widget with views scrolling left to right and right to left, depending on the direction of a user swipe.
Below is my mail.xml. Can someone suggest me how to make a horizontal scroller? When I change this layout it says: Problem loading widget. Please suggest me a solution.
<?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:layout_margin="4dp"
android:background="#drawable/background"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/widget1label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/widget1txt"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

I think HorizontalScrollView is what you're looking for. Simply wrap the element you want to scroll and it should work.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/heading_title"
/>
<ScrollView
android:id="#+id/layout"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:scrollbars="horizontal|vertical"
android:layout_width="fill_parent"
android:layout_marginTop="5dip"
android:scrollbarStyle="outsideInset"
android:fillViewport="true">
<HorizontalScrollView
android:id="#+id/horizontalView"
android:layout_height="fill_parent"
android:scrollbars="horizontal|vertical"
android:layout_width="wrap_content"
android:layout_marginTop="5dip">
............Place all your layouts, views, such as linear layouts, table layouts, etc, that are needed for your app. Note that the TextView for heading/title (see above) will be outside the scrollview, so it will always stay visible at the top. Remove this if not needed, or add there more views as needed .............
</HorizontalScrollView>
</ScrollView>

So the answer is:Creating the App Widget layout is simple if you're familiar with Layouts. However, you must be aware that App Widget layouts are based on RemoteViews, which do not support every kind of layout or view widget.
A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
FrameLayout
LinearLayout
RelativeLayout
GridLayout
And the following widget classes:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper

Related

TableLayout not receive background if i use HorizontalScrollView

I'm trying use TableLayout to make a table and is much informations to screen of smartphone, so i need of a Horizontal Scroll, but if i use HorizontalScrollView, the TableLayout and my button of the screen have the background blank, the background simply disappears. I try use ScrollView (vertical) in test and all work fine, so the problem is in HorizontalScrollView in my opinion.
I try to change the width to a number, for example, width:"450 dp" and all resolved, but to approximately "1400 dp" all returned... My table is very large, have approximately 21 columns, so they tableLayout is much higher of "1400 dp".
i'm losing the hope, trying anything and nothing resolved.
somebody help me.
image below:
TableLayout with all working, but with ScrollView vertical, cutting the table without horizontal scroll:
http://s11.postimg.org/k9hg1a79v/Screenshot_2015_02_19_15_43_56.png
TableLayout with HorizontalScrollView, all backgrounds missing, this is the problem, TableLayout, TableRow and button lost the background.
http://s4.postimg.org/iprnwxg65/2015_02_19_15_41_14.png
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/HorizontalScrollView1"
android:layout_width="match_parent"
android:background="#drawable/background_start_screen"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/table"
android:background="#drawable/border"
android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</TableLayout>
<Button
android:id="#+id/button1"
android:background="#drawable/button_deny_state"
android:layout_marginTop="20dp"
android:textColor="#FFFFFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="fechaTela"
android:text="Fechar" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
You have to inflate items to HorizontalScrollView one by one with using adapter. Firstly you have to learn adapter mecanism.
This is an adapter example for custom listView :
http://www.learn2crack.com/2013/10/android-custom-listview-images-text-example.html
This can helps to solve your problem :
https://code.google.com/p/androidbeginner/source/browse/trunk/andriod/src/slieer/com/layout/TableAdapter.java?r=48

how to get Horizontal and Vertical Scrollable list in android?

i am developing an android app where i am showing day wise channel schedule (multiple rows).
now in this i have to provide both vertical and horizontal scrollability.
vertical scrollability will be normal , but horizontal scrollability should be synchronized
that is when user scrolls horizontally all other rows should also be scrolled in a sync.
i tried using table layout but its not going good with my requirement and i have also tried TwoWayView but i am not able to sync the horizontal scrolling.
i would like to know i anyone have faced/solved the similar situation.
Any leads on this is highly appreciated.
xml for vertical and horizontal Scrolling :-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/vertical_scroll_view2">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/horizontal_scroll_view2">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="910dp"
android:id="#+id/scheduleContainer"
android:orientation="vertical"
/>
</HorizontalScrollView>
</ScrollView>
.....
xml for TwoWayView:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/weekday"
android:layout_height="fill_parent"
android:layout_width="40dp"
android:textSize="12dp"
android:textStyle="bold" />
<com.mobiotics.tvb_stb.utilityclasses.TwoWayView
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/hlist"
style="#style/TwoWayView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/weekday"
android:scrollbars="none"
android:drawSelectorOnTop="false"
tools:context="com.mobiotics.tvb_stb.activity.HomeScreenActivity" />
</RelativeLayout>
i am adding twoway list to linear layout .
If you can have a ListView, I would start there. Just drop the ListView into a HorizontalScrollView. Make sure to set the width of the HorizontalScrollView to wrap_content. I noticed you have it set to fill_parent.

2 RelativeLayouts in one layout

I've decided to use 2 RelativeLayouts for my app, one Layout for one portion of child Views on the screen to the left, the other for child Views to go to the right.
The problem is I don't know how to lay them out in XML so that the middle white space isn't included when I inflate my Layout.
This is what I want.
When I use 1 RelativeLayout, the middle white space is filled with the RelativeLayout, and I can't touch anything behind it.
Thank you very much for reading.
Do something similar to the following example.
This will create a LinearLayout with 2 RelativeLayouts using layout_weight to space the RelativeLayouts and then you can populate the RelativeLayouts with whatever you want.
The Buttons are just place holders for the example.
<?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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST2" />
</RelativeLayout>
</LinearLayout>

Will a TableLayout supply a vertical scrollbar?

Or will I have to incorporate a ScrollView into the TableLayout? Is this even possible? I want to dynamically create any number of rows for a screen, but need the rows to be scrollable.
I've been trying in vain to get this to work using LinearLayout for too long now, and think it's time to move either to TableLayout or RelativeLayout -- any comments on the preferability of one over the other?
You can use table layout within scroll layout then it is possible.
for example,
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
You can use table layout instead of Linear layout..
None of the "list"-style views will automatically do scrolling. LinearLayout, TableLayout, RelativeLayout, none of them do it because (like other people pointed out) it's so easy to wrap them in a ScrollView, it's just functionality that they don't need.
You have to specify a ScrollView for your TableLayout just as below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#ffffff"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<TableLayout
android:id="#+id/myTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:shrinkColumns="1"/>
</RelativeLayout>
</ScrollView>

ScrollView don't scroll?

I've a ScrollView / RelativeLayout / FrameLayout and I inside put programmaticaly some widgets.
Here is the gui xml :
<?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="fill_parent"
android:fillViewport="true"
android:background="#drawable/fond_app">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/titreAppli"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Big Application"
android:textStyle="bold"
android:textColor="#9b9b71"
android:textSize="15dp"
/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/out"
android:layout_below="#id/titreAppli"
/>
</RelativeLayout>
</ScrollView>
In the FrameLayout, I put programaticaly another RelativeLayout, and other widgets inside.
With some widgets (text, image, buttons), I can't scroll. With other (a linearlist with text), I can scroll.
Why ? Is there a solution ?
Thanks.
First remove frame layout. You should use some other layout like relative instead of framelayout. Becasue Framelayout is not expanding and there fore scroll view is not working. If you use linear or relative then they will expand and you will be able to scroll.
Have you tried without the android:fillViewport="true" ?

Categories

Resources