0

저는 내부 RelativeLayout과 함께 RelativeLayout을가집니다. 여기에는 왼쪽에는 TextView가 있고 오른쪽에는 ImageButton (별표)이 있습니다.ImageButton 겹침 문제

The whole layout

당신은 내가하여 ImageButton에 태그 layout_alignEnd 및 layout_alignRight을 설정하고있어 있지만하여 ImageButton 텍스트를 overlapps있는 볼 수 있듯이.

이 내 내부 RelativeLayout의이다 :

나는 텍스트를하여 ImageButton의 왼쪽과하여 ImageButton 결코 텍스트를 overlapps있는 없다는 것을 항상 것을 달성 할
<RelativeLayout 
    android:id="@+id/layout_question" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/toolbar" 
    android:layout_toEndOf="@+id/tv_topic" 
    android:layout_toRightOf="@+id/tv_topic" 
    android:gravity="top" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/tv_question" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textStyle="bold"/> 

    <ImageButton 
     android:id="@+id/bt_favorite" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignEnd="@+id/tv_question" 
     android:layout_alignRight="@+id/tv_question" 
     android:background="#00ffffff" 
     android:src="@drawable/star"/> 
</RelativeLayout> 

.

여기에 문제가 있습니까?

+0

이미지 버튼에'android : layout_alignBottom = "@ + id/tv_question"'을 사용하십시오. – knownUnknown

답변

1

그냥 당신이에 따라 가중치를 그냥이

<RelativeLayout 
    android:id="@+id/layout_question" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/toolbar" 
    android:layout_toEndOf="@+id/tv_topic" 
    android:layout_toRightOf="@+id/tv_topic" 
    android:gravity="top" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/tv_question" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_toLeftOf="@+id/bt_favorite" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textStyle="bold"/> 

    <ImageButton 
     android:id="@+id/bt_favorite" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:background="#00ffffff" 
     android:src="@drawable/star"/> 
</RelativeLayout> 
+0

감사합니다. 이것은 문제를 해결했다. –

1

선형을 기준으로 확인하려고 ImageView

android:layout_alignParentRight="true" 

layout_alignParentRight 속성을 사용하고, 조정 TextView

android:layout_toLeftOf="@+id/bt_favorite" 

layout_toLeftOf 속성을 사용 너의 요구 ment.

<LinearLayout 
     android:id="@+id/layout_question" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="top" 
     android:orientation="horizontal" 
     android:weightSum="6"> 

     <TextView 
      android:id="@+id/tv_question" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textStyle="bold" 
      android:layout_weight="5"/> 

     <ImageButton 
      android:id="@+id/bt_favorite" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_alignEnd="@+id/tv_question" 
      android:layout_alignRight="@+id/tv_question" 
      android:background="#00ffffff" 
      android:src="@mipmap/ic_launcher" 
      android:layout_weight="1"/> 
    </LinearLayout> 
1

기본적으로, 당신은 그 폭 원인 android:layout_alignParentLeft="true" 로 텍스트 뷰 (tv_question가) match_parent이다 설치에 필요 없어요. 따라서 텍스트 뷰를 이미지 뷰 옆에 놓고 싶다면이 작업을 수행하십시오. , 방향 : 안드로이드 - 먼저 당신이 당신의 RelativeLayout의의 ATTR을 설정할 필요 없다, 텍스트 뷰는 단지 마지막

<ImageButton 
    android:id="@+id/bt_favorite" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:background="#00ffffff" 
    android:src="@drawable/star"/> 
<TextView 
    android:id="@+id/tv_question" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_toLeftOf="@+id/bt_favorite" 
    android:padding="5dp" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textStyle="bold"/> 

이미지 뷰

의 왼쪽하자, 다음의 말을하자, 당신의 이미지 뷰의 위치를 ​​고정 우측 정렬하고, 그것은 작동하지 않습니다. 시도해보십시오. 작동해야합니다.