GridView不在Android 7上显示项目

时间:2017-03-02 16:54:09

标签: android gridview

我正在使用GridView来显示来自在线服务的图像。图片在7之前的Android版本上显示正常,但在Android N上,项目不显示。

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/colorPrimary"
tools:context="appfactory.app.movies.ui.GridFragment">


<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:elevation="4dp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:gravity="center"
            app:layout_collapseMode="pin"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal|bottom"
            android:orientation="vertical">

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center_horizontal"
                android:lines="1"
                android:textAllCaps="true"
                android:text="Movies"
                android:textAppearance="?android:textAppearanceLarge"
                android:textColor="@color/whiteDark"
                android:textSize="40sp"
                android:textStyle="bold"
                app:layout_scrollFlags="scroll|enterAlways" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/colorAccent"/>

        </LinearLayout>

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>


 <GridView
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:numColumns="2"
    android:background="@color/whiteDark"
    android:horizontalSpacing="0dp"
    android:verticalSpacing="0dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />


<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="gone"/>

<ImageView
    android:id="@+id/noNetImgVw"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_gravity="center"
    android:src="@drawable/nonet"
    android:visibility="gone"/>



<android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fab"
    style="@style/FAB"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="bottom|right"
    android:src="@drawable/next"
    app:borderWidth="0dp"
    app:elevation="6dp"
    app:pressedTranslationZ="12dp"
    app:rippleColor="@android:color/white"
    />

这是项目xml布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
    android:id="@+id/itemImg"
    android:layout_width="210dp"
    android:layout_height="300dp"
    android:transitionName="@string/pic_transition_name"/>

<TextView
    android:id="@+id/itemTxt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="9sp" >
</TextView>

这是适配器中的getView()方法:

    @Override
public View getView(int position, View view, ViewGroup parent) {
    // TODO Auto-generated method stub

    final ViewHolder viewHolder = new ViewHolder();

    item = gridData.get(position);

        view = LayoutInflater.from(mContext).inflate(R.layout.grid_item, parent, false);

        viewHolder.title = (TextView) view.findViewById(R.id.itemTxt);

        viewHolder.imageView = (ImageView) view.findViewById(R.id.itemImg);
        viewHolder.imageView.setImageResource(R.mipmap.ic_launcher);

        view.setTag(position);

        imgUrl = "http://image.tmdb.org/t/p/w500/" + item.getImage();
        Picasso.with(mContext).load(imgUrl).into(viewHolder.imageView);

     return view;
}

网格视图在屏幕上绘制,但项目未显示。感谢您的任何建议。

0 个答案:

没有答案