Skip to content Skip to sidebar Skip to footer

Scroll View Is Not Working Properly Android

I Want to create a design like this image . I want independent scroll on both left and right side What i have done that i have created a main layout .In that i am inflating the in

Solution 1:

I've had a look at the layout XML and have found your problem. In one layout you are trying to define both scrollviews and their contents. You don't want to be doing this. I would also suggest you don't want a scrollview, but a listview.

Take a look at This tutorial on how to create listviews with custom contents and create an arrayadapter to populate it with data.

This is an example of how your main layout could look:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:id="@+id/llHeader"android:orientation="vertical"android:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_weight="1"/><LinearLayoutandroid:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_weight="4"android:orientation="horizontal"><ListViewandroid:id="@+id/lvDepartures"android:layout_weight="1"android:layout_height="wrap_content"android:layout_width="wrap_content"/><ListViewandroid:id="@+id/lvArrivals"android:layout_weight="1"android:layout_height="wrap_content"android:layout_width="wrap_content"/></LinearLayout><LinearLayoutandroid:id="@+id/llFooter"android:orientation="vertical"android:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_weight="1"/></LinearLayout>

This gives you three vertical sections weighted DYNAMICALLY so it looks the same on any device screen in proportions 1:4:1. Then the middle section is split down the middle with two listviews which are independently scrollable which you can populate using an adapter.

Then you want to create a SINGLE layout for "a flight"

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"><ImageViewandroid:layout_width="75sp"android:layout_height="75sp"android:layout_marginRight="10sp"android:layout_marginTop="5sp"android:layout_marginBottom="5sp"android:id="@+id/ivDemoIcon"android:layout_alignParentTop="true"android:layout_alignParentLeft="true"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center_vertical"android:textAppearance="?android:attr/textAppearanceLarge"android:text="Demo Name"android:layout_marginTop="20sp"android:id="@+id/tvDemoName"android:layout_toRightOf="@+id/ivDemoIcon"android:layout_toLeftOf="@+id/ivChevron"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_toRightOf="@+id/ivDemoIcon"android:layout_toLeftOf="@+id/ivChevron"android:text="Date Version"android:id="@+id/tvDateVersion"android:textAppearance="?android:attr/textAppearanceSmall"android:layout_below="@+id/tvDemoName"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/ivChevron"android:layout_alignTop="@+id/ivDemoIcon"android:layout_alignParentRight="true"android:layout_alignBottom="@+id/ivDemoIcon"/></RelativeLayout>

This layout has space for two icons as well as three sections of text nicely layed out. You can move these about and create the layout as you want with the information you want. Always try and make layouts as generic as possible so you can use it over and over.

You can then use your adapter to populate each element of each listview for each flight with an instance of this "flight" layout (I've been too lazy to tweak it to be a flight layout like yours but you should get the gist).

You can then create a header and footer layout which the textviews and imageviews etc can be set at runtime accoring to what flight information you have. For the flight information, I would strongly suggest using a singleton data class accessible from anywhere and store the information in ArrayLists (Listview adapters etc play VERY nicely with arraylists and you can do all sorts of cool things like sorting and filtering)

The beauty of clever coding is making everything as dynamic and reusable as you can. Don't go hardcoding things or creating lots of layouts for the same thing, Reuse and recycle! Will make your job much easier. Hope this has helped

Post a Comment for "Scroll View Is Not Working Properly Android"