2017-10-18 8 views
0

私は女の子のファッションカテゴリを表示するアプリを開発しています。私はグリッドビューでカテゴリを表示しようとしました。しかし、私はアプリをテストすると、私はそれをスクロールしながらグリッドビューが壊れています。私のコードは以下のとおりです。これで私を助けてください。前もって感謝します。GridViewはスクロール中に壊れていますか?

enter image description here

single_item.xml

<?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:padding="10dp" 
android:orientation="vertical" 
android:gravity="center"> 

<ImageView 
    android:layout_width="150dp" 
    android:layout_height="150dp" 
    android:id="@+id/grid_image"/> 

<TextView 
    android:maxLines="1" 
    android:layout_marginTop="10dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/grid_text" 
    android:textColor="#000" 
    android:textSize="20sp" 
    android:gravity="center"/> 

</LinearLayout> 

activity_browse.xml 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context="com.example.user.beautyworld.BrowseActivity"> 


<GridView 
    android:id="@+id/grid_view" 
    android:layout_width="match_parent" 
    android:padding="10dp" 
    android:numColumns="auto_fit" 
    android:gravity="center" 
    android:columnWidth="150dp" 
    android:layout_height="match_parent"> 

</GridView> 

</LinearLayout> 

答えて

0

代わりLinearLayoutのこの目的のためにRelativeLayoutを使用することができます。

single_item.xml

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#2a2a2a" > 

<ImageView 
    android:layout_width="150dp" 
    android:layout_height="150dp" 
    android:id="@+id/grid_image"/> 

<TextView 
    android:maxLines="1" 
    android:layout_marginTop="10dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/grid_text" 
    android:textColor="#000" 
    android:textSize="20sp" 
    android:gravity="center"/> 

</RelativeLayout> 

activity_browse.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#2a2a2a" > 

<GridView 
    android:id="@+id/grid_view" 
    android:layout_width="match_parent" 
    android:padding="10dp" 
    android:numColumns="auto_fit" 
    android:gravity="center" 
    android:columnWidth="150dp" 
    android:layout_height="match_parent"> 

</GridView> 

</RelativeLayout> 

この答えはすでにhereを提供しました。

+0

まだ私は問題に直面しています –

関連する問題