2016-09-19 30 views
0

イメージの選択部分では、これらのイメージのリストは静的ですが、データベースから取得したイメージを動的に変更したいのです。これを行うには良い方法がありますか?listview listviewのアイテムをsqaure形式で表示するにはどうすればよいですか?

enter image description here

+0

このビューはスクロールされていません。これはリストビューを表すものではありません。それもなくして作ることができます。 – cafebabe1991

+0

あなたは私に解決策のヒントを教えてもらえますか?私はlistviewを使用しない場合、どのようにDBを介して動的に更新することができますか?これらの小さな画像はDBから来ているからですか? –

+0

gridviewを使ってそのように表示する –

答えて

1
<?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"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimaryDark" 
     android:orientation="horizontal"> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".6" 
      android:background="@color/colorPrimaryDark" 
      android:orientation="vertical"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_margin="5dp" 
       android:layout_weight="1" 
       android:src="@mipmap/ic_launcher" /> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_margin="5dp" 
       android:layout_weight="1" 
       android:src="@mipmap/ic_launcher" /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:gravity="center"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:src="@mipmap/ic_launcher" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".6" 
      android:background="@color/colorPrimaryDark" 
      android:orientation="vertical"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_margin="5dp" 
       android:layout_weight="1" 
       android:src="@mipmap/ic_launcher" /> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_margin="5dp" 
       android:layout_weight="1" 
       android:src="@mipmap/ic_launcher" /> 
     </LinearLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimaryDark" 
     android:orientation="horizontal"> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

    </LinearLayout> 
</LinearLayout> 

code result

あなたは、データベースから画像を取得し、このImageViewのそれぞれに設定することができます。

+0

ありがとう@Pawanpreet –

+0

ようこそ! @ A.Wahab – Pawanpreet

関連する問題