2013-01-09 3 views
2

나는 붉은 색 블록이 검은 색 영역의 중심에 배치되고 푸른 색 사각형이 흰 색과 붉은 색 블록의 가운데에 위치해야하는 레이아웃이 있습니다. 아무도 그러한 레이아웃의 틀을 만드는 방법을 알고 있습니까?android : 상대 레이아웃을 중심에 배치하는 방법은 무엇입니까?

당신은 당신의 목표를 달성하기 위해 귀하의 의견에 상대적으로 레이아웃의 특성 몇 함께 플레이해야

enter image description here

+0

android : layout_centerInParent = "true"' – user370305

답변

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" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@id/textView2" 
    android:layout_below="@id/textView1" 
    android:layout_centerHorizontal="true" 
    android:gravity="center_vertical" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

</RelativeLayout> 

textView2이 textView1 및 parentTop 이상 : 당신은 BlueBox 무엇이든의 매개 변수를 사용하여 상대 레이아웃에서 매개 변수를 혼합해야한다는 점 달성하기 위하여

, 여기에 사용 TextViews 예입니다 , 그래서 그것은 그 모든 공간을 차지할 것입니다. 그런 다음 자신의 내부 중력을 사용하여 Vertical을 중심에 배치하여 내용 중심으로 만듭니다.

+0

중간 텍스트 뷰의 배경을 설정할 수 있습니까? –

+0

이지만 높이는 장치 화면 크기와 방향에 따라 많이 달라집니다. 그렇게하면 시스템에서 자동으로 계산하도록 할 수 있습니다. – Budius

+0

동의하지만 OP의 게시물 (이미지)을 볼 때 중간 파란색 부분의 여백은 비례하지만 귀하의 경우에는 동일하지 않습니다. –

1

, 당신은 다음과 같은 것을 할 필요가 :

enter image description here

가 언급 한 속성을 적용하여 보기, 당신은 당신의 결과를 얻을 것이다. 자세한 정보를 원하시면

이 진정으로 질문에 대답 아래 링크를 다른 답변의

Relative layout

+1

답변에 문제가 있습니까? 왜 downvote? – RobinHood

+0

다른 모든 것과 동일합니다. 불완전한 대답. – Budius

+0

@Budius 그 우연히 일치하는 동안, 나와 함께 두 개의 답변도 게시되었고 그것의 유사하지 않은, 그리고 불완전에 관한, 내 대답을 편집합니다. – RobinHood

관련 문제