2012-08-01 65 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机器人:方向=“横向”是默认 – Blackbelt 2012-08-01 16:01:09

+0

啊非常感谢你 – MurphyApps 2012-08-01 16:01:52

+2

时fixs您的问题的答案,你应该接受它。 – Blackbelt 2012-08-01 16:02:35

2

您也可以使用,但皮棉说,如果它嵌套

它会影响你的表现

您可以像使用代码低于

<LinearLayout android:layout_height="wrap_content" 
    android:layout_width="fill_parent"> 
    <TextView android:layout_height="wrap_content" 
     android:layout_width="fill_parent" android:text="Slashdot" 
     android:id="@+id/textUser" android:layout_weight="1" 
     android:textStyle="bold"/> 
    <TextView android:layout_height="wrap_content" 
     android:layout_width="fill_parent" android:gravity="right" 
     android:layout_weight="1" android:id="@+id/textCreatedAt" 
     android:text="10 minutes ago"/> 
</LinearLayout> 

但是,如果你有它像下面的代码,林特会说它会影响你的表现。

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

    </LinearLayout> 

</RelativeLayout> 

您也可以使用Relative Layout,但不要使用weight。如果你把它们放在下面的代码中,你只需要管理边距。

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