Autore Topic: GridView dinamica in base al contenuto  (Letto 234 volte)

Offline galefabio

  • Nuovo arrivato
  • *
  • Post: 10
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S3
  • Sistema operativo:
    4.0.4
GridView dinamica in base al contenuto
« il: 05 Marzo 2014, 14:27:04 CET »
0
Ciao,

sto utilizzando ExpandableHeightGridView però non mi riesce a calcolare l'altezza giusta della gridview, io utilizzo delle righe custom, fatte da un layout esterno, ma mi vengono tagliate diverse righe in fondo,
ecco il codice:

Codice (Java): [Seleziona]
public class ExpandableHeightGridView extends GridView {

boolean expanded = false;

public ExpandableHeightGridView(Context context) {
    super(context);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs,
        int defStyle) {
    super(context, attrs, defStyle);
}

public boolean isExpanded() {
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (isExpanded()) {
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    } else {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

public void setExpanded(boolean expanded) {
    this.expanded = expanded;
}
}

Custom Row
Codice (Java): [Seleziona]
<?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:background="@null"
android:orientation="vertical" >

<TextView
    android:id="@+id/textViewBioAnno"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:gravity="center_horizontal"
    android:text="TextView"
    android:textColor="@color/oro"
    android:textSize="20sp" />

<TextView
    android:id="@+id/textViewBioTesto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="TextView"
    android:textSize="15sp" />

</LinearLayout>

Layout
Codice (Java): [Seleziona]
<?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:background="@color/sfondo"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="wrap_content"
                android:layout_height="80dp"
                android:layout_marginTop="10dp"
                android:scaleType="fitCenter"/>

            <ImageButton
                android:id="@+id/imageView1"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_margin="12dp"
                android:background="@null"
                android:scaleType="fitXY" />
        </RelativeLayout>

        <TextView
            android:id="@+id/textViewBio"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="@string/bio"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/oro" />

        <******.ExpandableHeightGridView
            android:id="@+id/mebersListGridView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="15dp"
            android:horizontalSpacing="10dp"
            android:isScrollContainer="false"
            android:numColumns="1"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:src="@drawable/fondo_pagina" />

        <ImageView
            android:id="@+id/ImageView02"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="70dp"
            android:layout_marginRight="70dp"/>

        <ImageView
            android:id="@+id/ImageView01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
            android:layout_marginRight="100dp"" />
    </LinearLayout>
</ScrollView>

</LinearLayout>

Activity
Codice (Java): [Seleziona]
...
g = (ExpandableHeightGridView) findViewById(R.id.mebersListGridView);
arrayAdapter = new StandardArrayAdapter(this,
            R.layout.activity_bio, arrayList);
g.setExpanded(true);
g.setAdapter(arrayAdapter);
...