2016-06-14 5 views
2

나는 뷰를 중심점으로 정렬하는 방법은 무엇입니까?

enter image description here

가 그럼 난이

Android - How do I position views in an offset relative to the center/top/bottom (etc.) of their parent?

그래서 내가없는이 레이아웃

<?xml version="1.0" encoding="utf-8"?> 
<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" 
    tools:context="com.myapplication.MainActivity"> 
    <View 
     android:id="@+id/square" 
     android:layout_width="100dp" 
     android:background="#ff0000" 
     android:layout_centerInParent="true" 
     android:layout_height="100dp"/> 
    <ImageView 
     android:id="@+id/circle" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignTop="@id/square" 
     android:layout_alignLeft="@id/square" 
     android:layout_marginRight="25dp" 
     android:layout_marginBottom="25dp" 
     android:src="@mipmap/circle" /> 
</RelativeLayout> 

그러나 레이아웃 여백을 만들어 발견이 레이아웃을 만들고 싶습니다 어떤 효과

출력은 다른보기의 특정 지점에 뷰의 중심점을 정렬하는 방법

<ImageView 
    android:id="@+id/circle" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_alignTop="@id/square" 
    android:layout_alignLeft="@id/square" 
    android:src="@mipmap/circle" /> 

에 동일?

+0

은 코드에서 수평 및 수직 작업의 중심입니까? 그것을 시도하십시오 –

+0

사각형 안에 서클을 배치 후, 최대 반경을 이동하고 왼쪽 –

답변

0

한 가지 옵션은 사각형에 여백을 제공합니다. 위쪽과 여백 왼쪽은 원의 반지름과 같습니다. 그것이 당신에게 도움이 될의 나, 두 요소는 내가 한 예를했을 alignParentLeft=true

+0

이것을 시도 했습니까? 그것이 효과가 있습니까? – therealprashant

1

안녕하세요 속성 보자

당신 폭을 알고있는 경우 출력

<FrameLayout 
       android:id="@+id/FrameMove" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="8dp"> 

       <LinearLayout 
        android:id="@+id/linearFramelayout" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginRight="5dp" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/frame_drawable" 
        android:gravity="center" 
        android:orientation="vertical" 
        android:paddingBottom="-50dp"> 

        <TextView 
         android:id="@+id/txtMove" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textColor="@android:color/white" 
         android:textSize="20sp" 
         android:textStyle="bold"/> 
       </LinearLayout> 


       <ImageView 
        android:id="@+id/imgClose" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="end|top" 
        android:layout_marginRight="-8dp" 
        android:layout_marginTop="-8dp" 
        android:src="@drawable/ic_action_close_white"/> 

      </FrameLayout> 

Output

+0

이 답변은 현재 레이아웃에는 적용하기 어렵지만 마지막으로 나는이 대답에서부터 영감을 얻어 안드로이드를 설정해야합니다 : layout_marginRight = "- 25dp", 그러면 문제가 해결되어 여전히 유용한 대답입니다. –

0

에 다음 코드를 확인하세요 서클 이미지의 높이가 낮 으면 framelayout을 사용하고 원의 너비와 높이 반쪽을 반으로 왼쪽 및 위쪽 여백을 지정해야합니다.

관련 문제