2016-03-27 10 views
-2

私は相対レイアウトでシンプルなカードを使用しています。 相対レイアウトで使用できますか?はいの場合はどうですか?Android Studioで相対レイアウトでcardViewを使用できますか?

+1

um、 'RelativeLayout'に入れてください。何を求めているのですか? –

+1

CardViewはViewGroupに過ぎません。通常のViewGroupのように、他のビューグループで使用できます。 –

答えて

1

次のようにRelativeLayout内部CardViewを使用する場合:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:background="@android:color/black" 
android:layout_height="match_parent"> 

    <android.support.v7.widget.CardView 
    ....> 
     <....>//Imagine a TextView here 
     <....> 
    </android.support.v7.widget.CardView> 
</RelativeLayout> 

、あなたは正しい方法でcardview内の要素をarrrageすることはできません。ホルダーとしてCardViewを想像要するに

、あなたはそれが正しい方法例えば

に動作させるためにCardView内部のレイアウトを使用する必要があります:

<android.support.v7.widget.CardView 
    ....> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:background="@android:color/black" 
    android:layout_height="match_parent"> 
      <....>//Imagine a TextView here 
      <....> 
    </RelativeLayout> 
</android.support.v7.widget.CardView> 
1

はい、我々は従ってください使用することができますコード:

<!-- About Panel --> 
<android.support.v7.widget.CardView 
    android:id="@+id/cv_About" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/cv_Help" 
    android:layout_gravity="center" 
    android:elevation="3dp" 
    app:cardCornerRadius="0dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="@dimen/pad_20dp"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:text="@string/about" 
      android:textColor="@color/dimblack" 
      android:id="@+id/tvAbout" 
      /> 

    </RelativeLayout> 

</android.support.v7.widget.CardView> 

乾杯!

関連する問題