2014-10-23 5 views
0

내 응용 프로그램 (지원 라이브러리 사용)에 카드보기가 있는데, 카드가 모두 한 행에 들어 가지 않으면 랩 어라운드를 원합니다. 현재 그들은 수직으로 쌓아 올리고 있습니다. 목록에서 유일한 요소 인 경우 랩을 수행 할뿐만 아니라 전체 상위 항목을 채울 수있는 방법이 있습니까?CardView wrapping

이상적으로 나는 한 줄에 두 장의 카드를 놓고 그 지점에서 새로운 줄로 감싸는 것이 좋습니다. recyclerview를 포함

보기 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/my_rootlayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<LinearLayout 
    android:id="@+id/my_window" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_centerInParent="true" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/my_headertext" 
     style="@style/roboto_header_text_black" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_centerHorizontal="true" 
     android:layout_gravity="center_horizontal" 
     android:layout_weight=".15" 
     android:gravity="center" 
     android:padding="@dimen/device_padding" 
     android:text="@string/en_us_my_header" 
     android:textIsSelectable="false" /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/my_list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight=".85" 

     /> 
</LinearLayout> 

CardView :

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:layout_width="250dp" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
card_view:cardCornerRadius="2dp"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:orientation="vertical"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/image_thumbnail" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" 
     android:gravity="center" 
     android:src="@drawable/default_image" 
     android:scaleType="centerCrop" 
     android:adjustViewBounds="true" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentStart="true" 
     android:background="#99000000" 
     android:gravity="center_vertical" 
     android:paddingLeft="8dp"> 

     <TextView 
      android:id="@+id/my_listitem_title_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:text="This is my title" 
      android:textColor="@color/white" 
      android:textSize="20sp" 
      android:fontFamily="sans-serif-light" 
      android:paddingLeft="8dp" 
      android:paddingRight="8dp" 
      android:paddingTop="4dp" 
      android:paddingBottom="4dp" /> 

    </LinearLayout> 
</RelativeLayout> 

    <ProgressBar 
     android:layout_width="match_parent" 
     android:layout_height="8dp" 
     android:indeterminate="false" 
     style="?android:progressBarStyleHorizontal" 
     android:progress="45" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" 
     android:paddingTop="2dp" 
     android:paddingBottom="2dp"> 
    <TextView 
     android:id="@+id/code_text_block" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@color/black" 
     android:textSize="14sp" 
     android:text="ABC" /> 

    <TextView 
    android:id="@+id/my_listitem_id_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="#123456" 
     android:textColor="@color/black" 
    android:layout_marginLeft="8dp" /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/my_listitem_date_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="14sp" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" 
     android:paddingTop="2dp" 
     android:paddingBottom="2dp" 
     android:text="Nov 5 - Nov 12, 2016" 
     android:textColor="#7D7D7D" /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" 
     android:paddingTop="4dp" 
     android:paddingBottom="4dp"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Download" 
      android:textAllCaps="true" 
      android:fontFamily="sans-serif" 
      android:textStyle="bold" 
      android:id="@+id/download_button" 
      android:background="@color/white" 
      android:textColor="@color/black" 
      android:paddingLeft="4dp" 
      android:paddingRight="4dp" 
      android:paddingTop="8dp" 
      android:paddingBottom="8dp" /> 
    </LinearLayout> 

</LinearLayout> 

답변

1

GridLayout을 @ random6174 said으로 사용해야하고이 code as guide을 사용하면 원하는대로 정확하게 수행 할 수 있습니다. 그것은 RecyclerView LayoutManager (MainActivity.java) 선언이 부분에

주의 :이 당신을 도움이되기를 바랍니다

mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView); 
mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); 
mRecyclerView.setLayoutManager(mLayoutManager); 

.

0

난 당신이 여기에 플로우 레이아웃을 사용할 수 있습니다 생각합니다. 내가 아는 한 안드로이드는 내장 된 플로우 레이아웃 클래스를 가지고 있지 않지만, 다른 곳에서 찾을 수있는 것들이 많이있다; 예 : this one.

하지만 같은 크기의 카드를 모두 표시하려면 GridLayout을 사용하고 프로그램에 따라 필요에 맞게 열 수를 조정할 수 있습니다.

행운을 빈다.

/편집 : Nevermind, 방금 CardView가 무엇인지 배웠습니다. 나는 네가 카드 놀이를하고 싶다고 생각했다. 어쩌면 흐름 레이아웃은 여전히 ​​당신에게 적합하지만 분명히 그 질문을 오해하고 있습니다. 내 잘못이야.