2015-02-03 2 views
0

저는 Android 개발을 처음 접했습니다. 색깔이있는 사각형을 추가하여 CardView 높이를 채우려고합니다. 여기 내 XML이있다.parent가 wrap_content 인 경우 match_parent가 발생합니까?

<android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="match_parent" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_height="wrap_content" > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" > 

      <View android:id="@+id/color_bar" 
       android:layout_width="50dp" 
       android:layout_height="match_parent" 
       android:background="#673AB7" /> 

      ... 

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

그러나 바는 카드에 표시되지 않습니다. match_parent에 대한 카드 높이를 얻지 못하는 것 같습니다 (높이가 dp 인 경우 표시됩니다). 이것은 카드의 높이가 wrap_content으로 설정되었거나 전혀 다른 것입니까? 나는 API (16)

편집에있어 : ​​저는 여기에 달성하기 위해 노력하고있어입니다 :

An image showing what I'm trying to achieve

그러나이 하드 코딩 (DP) 값으로 이루어졌다 및 장치에 확장되지 않습니다. 이 바를 카드 크기에 맞게 만들려고합니다.

+0

당신은 충돌 레이아웃 PARAMS을 지정할 수 없습니다 작동하는 것 같다. 자식이 match_parent를 가지고 있고 부모가 wrap_content를 가지고 있다면주기가 있습니다. – Zielony

+0

@Zielony 알겠습니다. 그건 의미가 있습니다. 내 목표를 다른 방향으로 달성하려면 어떻게해야합니까? –

+0

dp (50dp처럼)에 color_bar의 높이를 넣고'RelativeLayout'의 높이를'wrap_content'로 넣을 수 있습니다. 그것은 작동해야합니다 –

답변

0

어쩌면 LinearLayout에 중첩되어 weight을 사용할 수 있습니까? 매우 평평하지만

<android.support.v7.widget.CarView 
    ...> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal"> 
     <View 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="10" 
      android:background="#67BA37"/> 
     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="100" 
      ...> 
      ... 
      </RelativeLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

되지 않음

관련 문제