2016-08-04 1 views
0

내 애플 리케이션을 위해 내 텍스트보기에 대한 배경으로 4 개의 빈 팔각형을 원했습니다. 상대 레이아웃과 여백을 사용하여 올바른 위치에 textviews를 넣었습니다. 문제는 내가 작업 한 장치 (1020x1980) 이외의 다른 장치에서 텍스트 뷰가 중앙에서 벗어난다는 것입니다. 그래서이 문제를 해결할 수있는 유일한 방법은 dimens.xml 파일에서 장치 (ldpi, mdpi, hdpi, xhdpi 등)에 따라 다른 여백 값을 설정하는 것일까 요?백그라운드 아이콘 배치 assetview

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_vertical" 
android:background="@drawable/list_background" 
android:minHeight="?android:attr/listPreferredItemHeight"> 


<!--Info for the octagon icons--> 
<TextView 
    android:layout_width="83dp" 
    android:layout_height="44dp" 
    android:textColor="@color/orange_a400" 
    android:layout_marginLeft="53dp" 
    android:layout_marginTop="25dp" 


    android:textStyle="bold" 
    android:textSize="13sp" 
    android:text="Aug 24" 

    android:id="@+id/date" /> 

<TextView 
    android:layout_width="45dp" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="62dp" 
    android:layout_marginLeft="15dp" 

    android:textColor="@color/orange_a400" 
    android:textStyle="bold" 
    android:gravity="center" 
    android:text="105" 
    android:textSize="20sp" 
    android:id="@+id/sessionID" 

    /> 

<TextView 
    android:layout_width="45dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="24dp" 
    android:layout_toRightOf="@+id/sessionID" 
    android:layout_alignTop="@id/sessionID" 
    android:textColor="@color/orange_a400" 
    android:gravity="center" 
    android:textStyle="bold" 
    android:text="185" 
    android:textSize="20sp" 
    android:id="@+id/user_weight" 
    /> 
+0

레이아웃 컨테이너가되도록 각 팔각형을 디자인하고 가운데에'TextView'를 배치합니다. – Shaishav

+2

이것은 실제로 반 패턴입니다. 자신의 팔각형 배경을 가진 4 개의 textViews를 사용하고 상대 위치 지정을 사용해야합니다. –

+2

@Shaishav ... 다른 레이아웃? 왜? 중첩 레이아웃은 공연 **에 좋지 않습니다. TextViews는 자신의 배경을 가질 수 있습니다. 여분의 레이아웃에 대한 필요가 없습니다 ... –

답변

0

사용 위쪽과 왼쪽 위치 이렇게 배치의 순서, 내가 먼저 말을 텍스트 뷰를 추가하고이 위치를

ANDROID - positioning views programatically

설정을 참조 또한 다음 위치를 설정 이미지가 동적으로 위치를 설정 추가 및 의미
관련 문제