2014-03-01 3 views
0

내가 이렇게 될 내 응용 프로그램 내 버튼을 원하는 이동? 누군가가 내게 XML을 어떻게 실현할 수있는 간단한 예제를 줄 수 있습니까?어떻게 배치 할 요소는

고맙습니다.

+0

코드 없음, 해결책 없음. –

+0

코드가 없습니다. 나는 포토샵에서 내가하고 싶은 것을 보여주기 위해 이것을 만들었다. 어떤 레이아웃을 사용하는지 간단한 설명이나 아이디어가 좋을 것입니다. – user3367856

답변

0

분명히이 작업에는 여러 가지 방법이 있으며 FrameLayout, LinearLayout, RelativeLayout 등과 같은 다른 유형의보기 그룹을 조회하는 것이 좋습니다.

귀하의 질문에 관해서는 여기에 기본적인 접근 방식이 있습니다. 이제는 나와 함께 할 일이 많지 않으므로 이미지와 거의 비슷하게 보입니다.

LinearLayouts를 활용하여 레이아웃과 같은 "스태킹"을 사용합니다.

<?xml version="1.0" encoding="utf-8"?> 
<!-- LayoutA --> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <!-- LayoutB --> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <Button 
     android:layout_width="50dp" 
     android:layout_height="wrap_content" 
      android:text="A" /> 

     <Button 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:text="A" /> 

     <Button 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:text="A" /> 

     <Button 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:text="A" /> 
    </LinearLayout> 

    <!-- LayoutC --> 
    <LinearLayout 
     android:layout_gravity="center_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <Button 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:text="A" /> 

     <Button 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:text="A" /> 

     <Button 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:text="A" /> 

     <Button 
      android:layout_width="50dp" 
      android:layout_height="wrap_content" 
      android:text="A" /> 
    </LinearLayout> 

</LinearLayout> 

의 LinearLayout (A)이 수직으로 위쪽에서 "스택"것이다 개의 자식이 (방향 = "수직") 및 두 개의 자식 (B) 및 (C) "에 적층되어있는 버튼이 "왼쪽에서 수평으로 (orientation ="horizontal ").

아, 그리고 (C) 때문에 설정 중력의 화면의 중앙에 (layout_gravity = "center_horizontal") 당신이 당신의 버튼의 텍스트를 변경하는 경우, 당신이 중 하나를 만들기 위해 할 수

버튼의 너비를 넓히거나 wrap_content를 사용하십시오.

놀아보고 즐기십시오! :)

+0

고마워요! 그것은 많은 도움이되었습니다. layout_gravity의 값을 사용자 정의하는 방법이 있습니까? 그래서 레이아웃 (두 번째 버튼 라인)을 왼쪽 또는 오른쪽으로 몇 픽셀 이동시킬 수 있습니까? – user3367856

+0

예를 들어 레이아웃 C에서 layout_gravity를 사용할 필요는 없습니다. 대신 margin_left = "... dp"로 변경할 수 있습니다. 또는 함께 사용하여 전화기 화면 가운데에서 추가로 가져올 수 있습니다. 오, 당신은 반대편에 갈 것 인 마진에 음수를 넣을 수 있습니다. –

+0

이 두 가지 설정을 결합 할 수 있는지 알지 못했습니다. – user3367856

관련 문제