簡體   English   中英

Linearlayout錯誤地顯示按鈕

[英]Linearlayout displaying button incorrectly

我的布局只是一個小問題,當我在一個較小的設備(如手機)上運行我的應用程序時,它在平板電腦上渲染得很好。 其中一個按鈕似乎被其他按鈕“擠壓”並垂直渲染。

下面是問題區域的截圖

在此輸入圖像描述

我的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>

更改您的代碼如下。 您沒有設置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>   

在您的線性布局中添加參數'android:weightSum =“4”'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM