2014-12-06 3 views
0

안녕하세요 이미지보기에서 내 텍스트보기 중심에 문제가 있습니다. 나는 이것과 같이 보이기를 원하지만 실제로는 수직으로 가운데 맞추고 폰트 크기가 바뀌면 수직으로 머물러있게합니다. 여기 안드로이드 - 센터보기 다른보기 내부 레이아웃

enter image description here

그리고

내가 그냥이 중심을 할 수 있도록하려는 나에게 문제가되지 않는 다른 종류의 상대적 레이아웃을 변경해야하는 경우 난 상관 없어 XML에있는 것입니다. Heres the XML :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="com.spencer.app.ProfileActivity" 
android:id="@+id/layout"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:minHeight="140dp" 
    android:minWidth="140dp" 
    android:id="@+id/logoBackground" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginLeft="25dp" 
    android:layout_marginStart="25dp" 
    android:layout_marginTop="25dp" 
    android:contentDescription="@string/content_description_useless" 
    android:background="#ffffd0cd" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/capital_u" 
    android:id="@+id/u_textView" 
    android:textSize="80sp" 
    android:layout_marginLeft="31dp" 
    android:layout_marginStart="31dp" 
    android:layout_marginTop="20dp" 
    android:layout_marginBottom="20dp" 
    android:layout_alignTop="@+id/logoBackground" 
    android:layout_alignLeft="@+id/logoBackground" 
    android:layout_alignStart="@+id/logoBackground" /> 

</RelativeLayout> 

미리 감사드립니다.

+0

[Android - Centering Textview in Relative Layout] (http://stackoverflow.com/questions/27327367/android-center-textview-in-imageview-of-relative-layout) – tachyonflux

+0

게시물의 중복 가능 UR 원하는 이미지 pls .. –

+0

@MSGadag U를 제외하고 질문의 상단에 실제로 중심입니다! 아이디어를 보여주기 위해 드래그하여 최선을 다했습니다. – iqueqiorio

답변

0

당신의 문제는 당신이 뭔가 다른 것의 안쪽을 볼 센터링을하고 있지 않다는 것입니다.

가능한 해결책 중 하나는 TextView의 너비와 높이를 ImageView의 크기와 같게 설정하는 것입니다.

android:gravity="center" 

을 그러나 전반적으로,이 물건을 이런 종류의 작업을 수행하는 올바른 방법은 아닙니다 : 그런 다음 TextView의 XML이를 추가 할 수 있습니다.

android:background="@drawable/my_logo_background_image" 
1

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.spencer.app.ProfileActivity" > 

    <ImageView 
     android:id="@+id/logoBackground" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="25dp" 
     android:layout_marginStart="25dp" 
     android:layout_marginTop="25dp" 
     android:background="#ffffd0cd" 
     android:contentDescription="@string/content_description_useless" 
     android:minHeight="140dp" 
     android:minWidth="140dp" /> 

    <TextView 
     android:id="@+id/u_textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/logoBackground" 
     android:layout_alignLeft="@+id/logoBackground" 
     android:layout_alignRight="@+id/logoBackground" 
     android:layout_alignStart="@+id/logoBackground" 
     android:layout_alignTop="@+id/logoBackground" 
     android:text="@string/capital_u" 
     android:textSize="80sp" 
     android:gravity="center" /> 

</RelativeLayout> 
을 시도해보십시오 그릴 수로 또한 배경을 변경할 수 있습니다

android:background="#ffffd0cd" 

: 당신은 같은 것을 사용하여 TextView의 배경을 변경 오프 더 나은 것

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/layout" 
tools:context="com.spencer.app.ProfileActivity"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:minHeight="140dp" 
    android:minWidth="140dp" 
    android:id="@+id/logoBackground" 
    android:layout_marginStart="25dp" 
    android:background="#ffffd0cd" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="U" 
    android:id="@+id/u_textView" 
    android:layout_marginTop="30dp" 
    android:layout_marginLeft="45dp" 
    android:textSize="80sp" 
    android:layout_alignTop="@+id/logoBackground" 
    android:layout_alignLeft="@+id/logoBackground" 
    android:layout_alignStart="@+id/logoBackground" /> 

나는 그 일을 많이 바꾸지 않았다. 귀하의 코드를이 코드로 교체하십시오. :)

관련 문제