2017-07-10 21 views
0

私は今人気の映画を表示するアプリを開発しています。 TMDB APIを使用してこのデータをフェッチします。私はRecyclerViewを使用しています。このRecyclerViewは2列のグリッド内でクリック可能なImageViewを表示します。 これは私が達成したい結果である: an edge to edge grid of all movies私は唯一のハードコーディング値によって達成することができます:RecyclerViewにグリッドを正しく表示する方法は?

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content">` 

    <ImageView 
     android:layout_width="185dp" <!--HARDCODED VALUES--> 
     android:layout_height="278dp"<!--HARDCODED VALUES--> 
     android:contentDescription="@string/movie" 
     android:id="@+id/rv_image_view" /> 

</LinearLayout> 

私はlayout_width="match_parent"またはlayout_height="wrap_content"を使用している場合は、私は非常に奇妙な、歪んだ結果を得ることができます。 Like this one.これをどのように修正する必要がありますか?
重複としてマークしないでください。私はこれを広範囲に捜し、絶対に何も出てこなかった。

+0

あなたがhttps://github.com/rahulpandey/MovieDB/blob/master/を参照することができますapp/src/main/java/com/rahul/movie/db/view/RectangleImageView.javaこのクラス – Rahul

答えて

0

活動でこの

<?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="wrap_content" 
android:orientation="vertical" 
> 

    <ImageView 
    android:id="@+id/movies_item" 
    android:layout_width="185dp" 
    android:layout_height="278dp" 
    android:scaleType="fitXY"/> 

</LinearLayout> 

のようなレイアウトファイルを作成し、これを試してみてください。

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); 
    recyclerView.setHasFixedSize(true); 
    RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(), 2); 
    recyclerView.setLayoutManager(layoutManager); 
0
<?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="wrap_content" 
    android:orientation="vertical" 
    android:layout_margin="1dp"> 

    <ImageView 
     android:scaleType="fitXY" 
     android:id="@+id/movies_item" 
     android:layout_width="match_parent" 
     android:layout_height="180dp"/> 

</LinearLayout> 
+0

https://github.com/akshay3015/popular_movies_stage_one_udacity –

+0

まだ疑問がある場合は、これに従ってください –

関連する問題