2013-02-19 63 views
0

在我的应用程序在手机等较小设备上运行应用程序时,我的布局只是一个小问题,在平板电脑上呈现良好。其中一个按钮似乎被其他人“挤压”并垂直渲染。Linearlayout显示按钮不正确

继承人问题区域

enter image description here

我的XML是如下的屏幕截图。

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="8dp" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="78dp" 
      android:layout_height="78dp" 
      android:layout_alignParentTop="true" /> 

     <TextView 
      android:id="@+id/txtEventNameTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Event Name" 
      android:textSize="19dp" 
      android:textStyle="bold" 
      android:layout_below="@+id/imageView1" /> 

     <TextView 
      android:id="@+id/txtEventName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="16dp" 
      android:layout_below="@+id/txtEventNameTitle" /> 

     <TextView 
      android:id="@+id/txtEventDateTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Event Date" 
      android:textSize="19dp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtEventDate" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="16dp" /> 

     <TextView 
      android:id="@+id/txtEventTimeTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Event Time" 
      android:textSize="19dp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtEventTime" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="16dp" /> 

     <TextView 
      android:id="@+id/txtEventLocationTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Event Location" 
      android:textSize="19dp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtEventLocation" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="16dp" /> 

     <TextView 
      android:id="@+id/txtEventDetailsTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Event Details" 
      android:textSize="19dp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtEventDetails" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="16dp" /> 

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

    <Button 
      android:id="@+id/btnAddToCal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
         android:layout_marginBottom="20dp" 

      android:text="Add to Calendar" 
      android:layout_weight="1"/> 

     <Button 
      android:id="@+id/btnAddToMyEvents" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add to my Events" 
      android:layout_marginTop="20dp" 

      android:layout_weight="1" 
      android:layout_toRightOf="@+id/btnAddToCal" 

      /> 

     <Button 
      android:id="@+id/btnSendToTwitter" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Share" 
      android:layout_marginTop="20dp"    
      android:layout_weight="1" 
      android:minWidth="40dp" 

      /> 
     <Button 
      android:id="@+id/btnSendToMaps" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Get directions" 
         android:layout_marginTop="20dp" 

      android:layout_weight="1" 
      android:layout_toRightOf="@+id/btnAddToMyEvents" 

     /> 


    </LinearLayout>  

     <fragment 
      android:id="@+id/map" 
      android:layout_width="fill_parent" 
      android:layout_height="300dp" 
      class="com.google.android.gms.maps.SupportMapFragment" 
      android:layout_marginBottom="10dp" 
      /> 
    </LinearLayout> 

</ScrollView> 
+1

只是删除weightSum线的LinearLayout和按钮,只需使用layoutWeight = 1与layoutWidth = 0dp沿所有按钮。 – 2013-02-19 13:35:53

回答

2

更改您的代码如下。您没有设置weightSum,而是将wrap_content设置为您的按钮,这是使您的按钮以错误方式显示的问题。

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:measureWithLargestChild="true" 
     android:orientation="horizontal" 
     android:weightSum="4"> 
<Button 
     android:id="@+id/btnAddToCal" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
        android:layout_marginBottom="20dp" 

     android:text="Add to Calendar" 
     android:layout_weight="1"/> 

    <Button 
     android:id="@+id/btnAddToMyEvents" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="Add to my Events" 
     android:layout_marginTop="20dp" 

     android:layout_weight="1" 
     android:layout_toRightOf="@+id/btnAddToCal" 

     /> 

    <Button 
     android:id="@+id/btnSendToTwitter" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="Share" 
     android:layout_marginTop="20dp"    
     android:layout_weight="1" 
     android:minWidth="40dp" 

     /> 
    <Button 
     android:id="@+id/btnSendToMaps" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="Get directions" 
        android:layout_marginTop="20dp" 

     android:layout_weight="1" 
     android:layout_toRightOf="@+id/btnAddToMyEvents" 

    /> 
</LinearLayout> 
+1

作为对此答案的快速解释,请勿使用“wrap_content”作为按钮宽度。建议使用0dp作为TNR。另一方面,weight_sum在所有权重相等或某种比例的情况下不是必需的。 – 2013-02-19 12:41:17

0

添加参数 '机器人:weightSum = “4”' 你的线性布局