2011-04-10 3 views
0

ImageView의 위치를 ​​어떻게 설정할 수 있습니까? 예를 들어 x = 150 및 y = 150에서 원하십니까?ImageView 위치

<ImageView android:id="@+id/ImageViewYellow" 
android:src="@drawable/yellocircle" 
android:scaleType="fitCenter" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"></ImageView> 

답변

0

사용자가 귀하의 응용 프로그램을 실행할 화면 크기를 모르기 때문에 150px 왼쪽 상단에 놓으면 예측할 수 없습니다. 당신이 뭔가를 할 수있는 RelativeLayout의를 사용할 수 있습니다

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#808080" 
    > 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:src="@drawable/circle" 
     /> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/circle" 
     /> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:src="@drawable/circle" 
     /> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/circle" 
     />   
</RelativeLayout> 

주는 :

Four Aligned Corners

는 이미지가 나란히 맞게 너무 큰있어 경우이 떨어져 떨어질 것이라는 점을 명심하십시오. 특정 화면 비율로 ImageView를 그려 축소하고, FrameLayout 내의 ImageViews의 layout_gravity를 top|left, top|right, bottom|leftbottom|right으로 설정하기 위해 코드에 무언가를 작성할 수 있습니다.

0

그것은에있는 뷰 그룹의 종류에 따라 달라집니다. 당신이이 AbsoluteLayout (사용되지 않음), 당신은 AbsoluteLayout.LayoutParamsxy 매개 변수를 사용하여 지정할 수 있습니다 사용하는 경우. FrameLayout을 사용하면 layout_margin* 매개 변수를 사용하여 위치를 제어 할 수 있습니다. 또는 ViewGroup을 하위 클래스 화하여 사용자 정의 레이아웃 관리자를 정의 할 수 있습니다.

+0

FrameLayout을 어떻게 사용할 수 있습니까? 이처럼 4 개의 동그라미 (각 원은 그림 임) 중간 위, 왼쪽, 오른쪽, 중간 아래를 배치해야합니다. – edprog

0

당신은

android:layout_x="150px" 
android:layout_y="150px" 

를 사용할 수 있지만 테드 후프 잘, 그것은 부모 요소 사양에 따라 달라집니다.