0

json データを解析して表示する 6 つの列を含むグリッド ビューの中に相対レイアウトがあるという私のシナリオを考えてみましょう。それは正常に動作します。しかし、下にさらに多くの行を追加すると、そのためにスクロールビューアーが保持されました。問題は、まず詳細が正しく表示されていることです。しかし、スクロール後に値が変化し、適切な方法で表示されません。つまり、テーブル値の順序は json からのものであるため、正確ではありません。スクロールごとに異なります (1 番目の値は 3 桁目、2 番目の値は 6 桁目など)。正確な問題が何であるかはわかりません。助けてください..

また、もう 1 つ小さな問題があります。アプリのヒープ サイズが増え続けています (現在、742M のうち 373M を示しています)。解決策を確認しました。コード android:largeHeap="true" を追加しようとしましたが、これも機能していません。

前進 解決策をありがとう!!

4

1 に答える 1

1

カスタム Gridview ExpandableHeightGridViewを使用してスクロール ビュー内にグリッド ビューを追加するには

以下の例に従ってください

ExpandableHeightGridView.java

        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)
{
    // HACK! TAKE THAT ANDROID!
    if (isExpanded())
    {
        // Calculate entire height by providing a very large height hint.
        // But do not use the highest 2 bits of this integer; those are
        // reserved for the MeasureSpec mode.
        int expandSpec = MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >> 2, 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;
}
}

XML ファイル

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scroll"
android:background="@android:color/white" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white" >


     <RelativeLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@android:color/white" >

    <TextView
        android:id="@+id/txbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="9dp"
        android:text="Textview"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#2c627e"
        android:textStyle="bold" />
</RelativeLayout>


    <yourpackagename of ExpandableHeight.class.ExpandableHeightGridView
        android:id="@+id/gridlist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:horizontalSpacing="10dp"
        android:layout_below="@+id/header"
        android:numColumns="2"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbars="vertical"
        android:verticalScrollbarPosition="right"
        android:verticalSpacing="10dp" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="#034E6D"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:id="@+id/view_rl"
        android:layout_below="@+id/gridlist" >

        <!--
         <TextView
        android:id="@+id/newsdata_grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/newsdatas"

        android:text="juijb"
        android:maxLines="3"
        android:layout_marginLeft="10dp"
        android:textSize="20dp" />
        -->

        <ImageView
            android:id="@+id/datas_images"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:src="@drawable/bike_icon" />

        <TextView
            android:id="@+id/data_grids"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/datas_images"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:text="VIEWS"
            android:textColor="@android:color/white"
            android:textSize="10dp" />
    </RelativeLayout>
    <View android:layout_width="fill_parent"
        android:layout_height="10dp"
        android:background="@android:color/white"
        android:layout_below="@+id/view_rl"/>
</RelativeLayout>

そしてActivityクラスでは

    ExpandableHeightGridView gridview=(ExpandableHeightGridView)findViewById(R.id.gridlist);
    gridview.setExpanded(true);

これにより、スクロールビュー内にグリッドビューが表示されます。これが役立つことを願っています

于 2013-12-12T11:06:40.597 に答える