2014-02-13 2 views
2

저는 Android 개발을 처음 접했습니다. 저는 오랫동안 iOS에서 일해 왔습니다. iOS 에서처럼 VIOB을 정확한 위치에 xib에 놓고 싶을 때 간단히 그 위치에 놓고 그 지점까지 끌어다 놓습니다. 예를 들어안드로이드 대 iOS의 뷰 위치?

가 중간에 enter image description here

아래, 단순히 그들을 원하는처럼 아이폰 OS에서 낮은 영역에서 두 개의 버튼을, 말을, 나는 그들 자신을 넣어 것입니다. 안드로이드 환경에서

enter image description here

지금 같은 일을 다음과 같이, 나는 경우

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/db1_root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/myAwesomeTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="1dip" 
     android:layout_centerInParent="true" 
     android:text="Veer Suthar" /> 

    <TextView 
     android:id="@+id/myAwesomeTextView1" 
     android:layout_width="wrap_content" 
     android:layout_height="100dip" 
     android:layout_below="@id/myAwesomeTextView" 
     android:layout_centerInParent="true" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/myAwesomeTextView1" 
     android:gravity="center_vertical" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/button1" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal|center" 
      android:onClick="buttonPressed" 
      android:text="Button One" /> 

     <Button 
      android:id="@+id/button2" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal|center" 
      android:onClick="buttonPressed" 
      android:text="Button Two" /> 
    </LinearLayout> 

</RelativeLayout> 

그것은 지금 아래

enter image description here

같은 활동 화면을 보여주고, 코드를 다음에 갈 GRAPHICAL LAYOUT을 사용하여 버튼을 드래그하고 싶습니다. m 원하는대로, 그리고 낮은 간격으로 넣으려면 간격을 두어야합니다. TextView.

iOS와 같이 Android 활동 GUI를 올바르게 구성하는 더 좋은 방법이 있습니까?

+0

이제 화면 중간이나 하단에 원 하시겠습니까? –

+2

정직하게 안드로이드 그래픽 레이아웃은 xCode처럼 잘 작동하지 않습니다. 필자는 개인적으로 안드로이드에서 코드로 그것을 선호합니다. –

+0

정확히 내가 원하는 것은 아니지만, iOS에서 할 수있는 것처럼 그래픽보기로 드래그 앤 드롭하고 싶습니다. Android에서 할 수 있습니까? –

답변

0

Android 그래픽 레이아웃이 Xcode만큼 매끄럽지 않기 때문에 간단한 예를 들어 보겠습니다.

화면에 두 개의 버튼을 중심으로, 당신이 필요 달성하기 위해이 같은 XML 코드를 사용할 수 있습니다 :

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

    <LinearLayout 
     android:id="@+id/layout_center" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_centerInParent="true"> 

     <Button 
      android:id="@+id/button_one" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button One"/> 

     <Button 
      android:id="@+id/button_two" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button Two"/> 
    </LinearLayout> 

</RelativeLayout> 

트릭은 중앙에 할 수있는 유일한 구성 요소에 대한 android:layout_centerInParent="true"을 사용하는 것입니다 화면에서 다른 모든 구성 요소는 화면에 참조를 위해 사용할 수 있습니다. 예를

<TextView 
    android:id="@+id/myAwesomeTextView1" 
    android:layout_width="wrap_content" 
    android:layout_height="100dip" 
    android:layout_above="@+id/layout_center" 
    android:text="Veer Suthar"/> 

이 들어

는이 작업을 수행하는 방법 중 하나입니다, 당신은 항상 일을 할 수있는 더 좋은 더 이해할 수있는 방법을 찾을 수 있습니다. 도움이 되었기를 바랍니다.