2012-08-01 5 views
0

"실행"과 "결과"라는 두 개의 버튼을 나란히두고 싶습니다. 그러나 나는별로 행운이 없다.XML - 두 개의 버튼을 나란히 놓는 방법?

나는 RelativeLayout을 사용하고 두 버튼 모두에 layout_weight을 추가하려고 시도했지만 화면이 사라지는 것처럼 보입니다.

누구나 내가 잘못하고있는 것을 지적하고 해결하기 위해 무엇을 할 수 있습니까?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


     <TextView 
      android:id="@+id/myLocationText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/hello" /> 
     <TextView 
      android:id="@+id/resultsHomeTest" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" /> 


     <Button 
      android:id="@+id/btnRun" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

      android:text="Run" /> 


     <Button 
      android:id="@+id/btnResults" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Results" /> 

     <TextView 
      android:id="@+id/resultsTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 


    <com.google.android.maps.MapView 
    android:id="@+id/myMapView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:enabled="true" 
    android:clickable="true" 
    android:apiKey="02kgJwy0ijcQsVCaCzD9sFv69dOi4gXBEUjIbuQ" 

    /> 

    <!-- 

    Desktop key: 02kgJwy0ijcTK7fd-wxv7OsPUFEveXTUt16lrRA 
    Laptop key : 02kgJwy0ijcQsVCaCzD9sFv69dOi4gXBEUjIbuQ 
     --> 
</LinearLayout> 

답변

0

랩 수평 LinearLayout 내부에 두 개의 버튼 :

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:orientation="horizontal"> 


    <Button 
       android:id="@+id/btnRun" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:text="Run" /> 


      <Button 
       android:id="@+id/btnResults" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Results" /> 
    </LinearLayout> 
+0

@csmit 안드로이드는 : 오리엔테이션 = "수평"문제 fixs 대답은, 당신이 그것을 받아 들여야 할 때 아, 당신에게 – Blackbelt

+0

입니다. – MurphyApps

+2

대단히 감사합니다 기본 – Blackbelt

2

또한 사용할 수 있지만 보풀이이

중첩되는 경우 귀하의 성능에 영향을 미칠 것이라고 말할

당신은 코드처럼 사용할 수 있습니다 아래

만약 당신이 아래의 코드를 좋아한다면, 그것은 귀하의 실적에 영향을 미칠 것입니다.

<RelativeLayout> 
    <LinearLayout> 
     <LinearLayout> 
      <ImageView 
      android:layout_weight="0.3"/> 
     </LinearLayout> 

    </LinearLayout> 

</RelativeLayout> 

상대 레이아웃을 사용할 수도 있지만 가중치를 사용하지 마십시오. 아래 코드와 같이 배치하면 마진을 관리하기 만하면됩니다.

<?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" > 
    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="Button" /> 



    <Button 
     android:id="@+id/button2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/button1" 
     android:text="Button" /> 

</RelativeLayout> 
관련 문제