2017-08-05 11 views
3

リストビューで連絡先を一覧表示すると、画像を表示する必要があります。各行項目の連絡先名、電話番号、コールアイコン。リストビュー行を3列に分割し、アンドロイドで垂直方向に2列に分割する方法

各行は3つの列に分割する必要があります。 最初の列には連絡先イメージがあり、2番目の列は垂直に2つに分割されます。最初は連絡先名、もう1つは番号です。 となり、最後の列にアイコン/イメージが表示されます。

required layout

私は以下試してみました。必要なフォーマットを取得できません。 (gridviewの代わりに)私たちは以下のようにtrtiedしたので、これはListviewで可能ですか?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ListView 
     android:id="@+id/listView_all_cont" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#a556f4" 
     android:scrollbars="horizontal"/> 


    <ImageView 
     android:id="@+id/imgView_contImg" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="@dimen/activity_horizontal_margin" 
     android:src="@drawable/no_image" /> 

    <TextView 
     android:id="@+id/txtView_name" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginStart="@dimen/activity_horizontal_margin" 
     android:textColor="#ffffff" 
     android:textSize="18sp" /> 

    <TextView 
     android:id="@+id/txtView_number" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginStart="@dimen/activity_horizontal_margin" 
     android:textColor="#ffffff" 
     android:textSize="14sp" /> 

</LinearLayout> 

ここで助けてもらえますか?

答えて

1

はい、ListViewで可能です。 RecyclerViewについて学ぶことをお勧めします。 RecyclerViewListViewの代わりにmoreを付けます。 item_row.xmlを1つ作成し、その行項目をAdapterに追加してください。このコードを試してください。

item.row.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="105dp"> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight=".3"> 

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

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight=".7" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:text="Text1" 
       android:paddingLeft="10dp" 
       android:gravity="center_vertical"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:text="Text1" 
       android:paddingLeft="10dp" 
       android:gravity="center_vertical"/> 
     </LinearLayout> 

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

あなたが持つことができ、あなたのActivityまたはこのようなFragmentレイアウト、

main_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ListView 
     android:id="@+id/listView_all_cont" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#a556f4" 
     android:scrollbars="horizontal"/> 


</LinearLayout> 

リスト項目のレイアウトlist_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="8dp" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:paddingTop="8dp"> 

    <ImageView 
     android:id="@+id/user_image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/ic_action_name"/> 

    <ImageView 
     android:id="@+id/action_image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/ic_action_name"/> 

    <TextView 
     android:id="@+id/name_tv" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/action_image" 
     android:layout_toRightOf="@+id/user_image" 
     android:padding="5dp" 
     android:text="XYZ"/> 

    <TextView 
     android:id="@+id/number_tv" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/name_tv" 
     android:layout_toLeftOf="@+id/action_image" 
     android:layout_toRightOf="@+id/user_image" 
     android:padding="5dp" 
     android:text="12345"/> 

</RelativeLayout> 

あなたも

RecycleViewを試すことができます
関連する問題