mercredi 15 juin 2016

using com.devsmart.android.ui.HorizontalListView library how to set wrap content programatically

I have a linear layout in xml with vertical orientation.

LinearLayout linearLayoutRoot = (LinearLayout)findViewById(R.id.listViewCompareLinear);

I used com.devsmart.android.ui.HorizontalListView library for horizontal ListView scroll. I need to call a no. of the horizontal scroll view programatically and add it to linear layout above (since it is dynamic, i cannot use through xml).

I did the following:

for (int k = 0; k < selectBike.size(); k++) {
    listView = new HorizontalListView(this, null);
    linearLayoutRoot.addView(listView);
}

But what happen is it displays only first HorizontalListView since i think it is set to match parent by default. I set the background color to the HorizontalListView and whole device screen is covered with that color. So setting it to wrap_content might solve the problem...

How to set the width to wrap content programmatically?

whole xml :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/horizontalListViewRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
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:context="com.bajaj.pulsar.pulsar.CompareListView">


    //it contains listViews dynamically
    <LinearLayout
        android:id="@+id/listViewCompareLinear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical">

    </LinearLayout>


<Button
    android:id="@+id/compare"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:paddingLeft="100dp"
    android:paddingRight="100dp"
    android:text="Compare" />


    </RelativeLayout>

Aucun commentaire:

Enregistrer un commentaire