2017-01-29 1 views
2

가로로 정렬 된 텍스트 뷰와 다른 이미지 뷰 아래에 배치 된 이미지 뷰를 만들어야합니다. 문제는 그들이 수평으로 정렬되지 않는다는 것입니다. 어떻게 내가이 문제를 방지하기 위해 일을해야 ..android 이미지 뷰 아래에 객체 배치

은 무슨 지금 일어나고 :
enter image description here

을 그것은 다음과 같이해야한다 :
enter image description here

내 코드 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:padding="5dp" 
    > 
    <ImageButton 
     android:id="@+id/imgBtnItem" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:background="@android:color/transparent"> 
    </ImageButton> 

    <TextView 
     android:id="@+id/txtName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textStyle="bold" 
     android:textSize="9sp" 
     android:layout_below="@+id/imgBtnItem"> 
    </TextView> 
    <ImageButton 
     android:id="@+id/imgBtnAdd" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imgBtnItem" 
     android:layout_toRightOf="@+id/txtName" 
     android:background="@android:color/transparent" 
     > 
    </ImageButton> 
</RelativeLayout> 

답변

1

다음과 같이 사용 (편집자 사용법에 따라 치수를 변경하십시오) :

<?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="match_parent" 
android:gravity="center" 
android:padding="5dp" 
> 
<ImageButton 
    android:id="@+id/imgBtnItem" 
    android:layout_width="150dp" 
    android:layout_height="150dp" 
    android:adjustViewBounds="true" 
    android:scaleType="fitCenter" 
    android:background="@color/colorAccent"> 
</ImageButton> 

<TextView 
    android:id="@+id/txtName" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:textStyle="bold" 
    android:textSize="9sp" 
    android:layout_marginTop="4dp" 
    android:layout_below="@+id/imgBtnItem" 
    android:background="@color/colorPrimary"> 
</TextView> 
<ImageButton 
    android:id="@+id/imgBtnAdd" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:background="@color/colorPrimaryDark" 
    android:layout_below="@+id/imgBtnItem" 
    android:layout_alignTop="@id/txtName" 
    android:layout_toEndOf="@id/txtName" 
    android:layout_alignEnd="@+id/imgBtnItem"> 
</ImageButton> 
</RelativeLayout> 

출력 :

enter image description here

+0

당신이 한 일은 잘 모릅니다. 나는 아직도 안드로이드 레이아웃을 디자인하는 것을 정말로 싫어한다. 도와 줘서 고마워! – zxc

+0

@zxc, 레이아웃을 서로 관련되게 사용하려면 relativelayout을 사용하십시오. 아래의 각 항목이 기본 이미지 뷰와 관련되는 경우에도 동일한 작업을 수행했습니다. – W4R10CK

1

다음과 같은 XML 코드를 시도 할 수 있습니다. 나는 이것을 달리고 그것은 잘하고있다. 테스트 용 아이콘과 텍스트를 추가하여 필요에 따라 변경할 수 있습니다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:padding="5dp" 
    > 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <ImageButton 
      android:id="@+id/imgBtnItem" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:scaleType="fitCenter" 
      android:background="@android:color/transparent" 
      android:src="@mipmap/ic_launcher"> 
     </ImageButton> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="1"> 

      <TextView 
       android:id="@+id/txtName" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:textStyle="bold" 
       android:textSize="9sp" 
       android:layout_below="@+id/imgBtnItem" 
       android:text="Hello" 
       android:layout_weight="0.7"> 
      </TextView> 

      <ImageButton 
       android:id="@+id/imgBtnAdd" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/imgBtnItem" 
       android:layout_toRightOf="@+id/txtName" 
       android:background="@android:color/transparent" 
       android:src="@drawable/abc_btn_check_to_on_mtrl_015" 
       android:layout_weight="0.3"> 
      </ImageButton> 
     </LinearLayout> 
    </LinearLayout> 
</RelativeLayout> 
1

이 테스트 코드를 사용하십시오. 간단한 레이아웃의 상대 레이아웃을 사용하지 마십시오. 그것은 좋은 연습이 아니에요

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:padding="5dp"> 

    <ImageButton 
     android:id="@+id/imgBtnItem" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:background="@android:color/transparent" 
     android:scaleType="fitCenter" 
     android:src="@drawable/amojee_logo"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:gravity="center"> 

     <TextView 
      android:id="@+id/txtName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="9sp" 
      android:text="hi how are you" 
      android:textStyle="bold"/> 

     <ImageButton 
      android:id="@+id/imgBtnAdd" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:src="@drawable/amojee_logo" 
      android:background="@android:color/transparent" /> 
    </LinearLayout> 


</LinearLayout> 
관련 문제