2012-10-04 6 views
17

일부 이미지 버튼이 있고 각각에 해당하는 textview가 있습니다. 텍스트 뷰를 해당 이미지 뷰의 중심에 정렬하고 싶습니다. 어플 서랍 ...android - 다른 뷰 중앙에 텍스트 뷰 정렬

!-----! 
!icon ! 
!_____! 
app name 

이, 나는 RelativeLayout

<ImageButton 
    android:id="@+id/blog_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/logo_img" 
    android:layout_marginLeft="50dp" 
    android:layout_marginTop="51dp" 
    android:background="@null" 
    android:contentDescription="@string/blog_desc" 
    android:src="@drawable/blog" /> 

<TextView 
    android:id="@+id/blog_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/blog_button" 
    android:layout_below="@+id/blog_button" 
    android:layout_marginTop="8dp" 
    android:text="@string/blog_desc" /> 

답변

28

랩을 내 코드를 사용하고있다있는 LinearLayout 및 센터 아이들에서, 그래서 같은 :

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/logo_img" 
    android:gravity="center_horizontal" 
    android:orientation="vertical"> 

    <ImageButton 
     android:id="@+id/blog_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:contentDescription="@string/blog_desc" 
     android:src="@drawable/blog" /> 

    <TextView 
     android:id="@+id/blog_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="@string/blog_desc" /> 
</LinearLayout> 
+0

덕분에 달성 할 수 투명하게 할 수 있다면! 내가 어떻게 생각하지 않았 니? 하위 레이아웃 ... 아직 배우고 있지만 지금 바보 같아요 :/ – Hairo

+3

Jason, 나중에 참조 용으로 ['FrameLayout'] (http://developer.android.com/reference/android/widget/ FrameLayout.html)은 일반적으로 여러 자식을 보유하는 데 사용해서는 안됩니다. 이 경우 LinearLayout이 가장 좋은 대안이 될 것입니다. – Eric

+0

필자는 어쨌든'FrameLayout'을 사용하지 않을 계획 이었지만 설명해 주셔서 감사합니다. – Hairo

14

이전 게시물이 도움이 될 수 있다면 추가 컨테이너를 추가 할 필요가 없다고 생각합니다.

<ImageButton 
    android:id="@+id/blog_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/logo_img" 
    android:layout_marginLeft="50dp" 
    android:layout_marginTop="51dp" 
    android:background="@null" 
    android:contentDescription="@string/blog_desc" 
    android:src="@drawable/blog" /> 

<TextView 
    android:id="@+id/blog_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/blog_button" 
    android:layout_alignRight="@+id/blog_button" 
    android:layout_below="@+id/blog_button" 
    android:gravity="center_horizontal" 
    android:layout_marginTop="8dp" 
    android:layout_marginLeft="-20dp" 
    android:layout_marginRight="-20dp" 
    android:text="@string/blog_desc" /> 

저에게 도움이됩니다.

1

a를 텍스트 뷰는 다음이 하나의보기

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Test string" 
    android:drawableTop="@android:drawable/btn_star" 
    android:background="@android:color/transparent" 
    android:textSize="10sp" 
    />