2013-02-19 163 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」' 你的線性佈局