2017-05-17 18 views
1

我佈局的設計同樣是不會在Android Studio中預覽和在運行的應用程序相同:Android的佈局設計不是當應用程序正在運行

設計在運行應用程序

enter image description here

預期設計

enter image description here

這裏的XML文件:

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

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:text="Manage messages" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/bt_messages" 
      android:drawableLeft="@mipmap/ic_message" 
      android:layout_weight="1" /> 

     <Button 
      android:text="Manage activities" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/bt_activities" 
      android:drawableLeft="@mipmap/ic_activities" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</LinearLayout> 

你有沒有發生什麼事的想法?

在此先感謝您的幫助

+0

'的android:layout_width = 「0dp」'兩個按鈕 –

+1

是,圖像尺寸是相同的兩個 –

+0

@IntelliJAmiya我想是這樣,我創造了他們在Android剪貼畫,他們在不同大小的5次mimap包中。 我編輯的兩個按鈕的layout_width,沒有任何改變 – Alexandre

回答

1

你可以這樣做

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

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

    <Button 
     android:text="Manage messages" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/bt_messages" 
     android:drawableLeft="@mipmap/ic_message" 
     android:layout_weight="1" /> 

    <Button 
     android:text="Manage activities" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/bt_activities" 
     android:drawableLeft="@mipmap/ic_activities" 
     android:layout_weight="1" /> 
</LinearLayout> 

0

你可以試試這個:

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

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:weightSum="1"> 

     <Button 
      android:text="Manage messages" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/bt_messages" 
      android:drawableLeft="@mipmap/ic_message" 
      android:layout_weight=".5" /> 

     <Button 
      android:text="Manage activities" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/bt_activities" 
      android:drawableLeft="@mipmap/ic_activities" 
      android:layout_weight=".5" /> 
    </LinearLayout> 

</LinearLayout> 
1

你應該在的地方 android:layout_weight使用android:weightSum你的內心LinearLayout
你也應該補充android:layout_width="0dp"爲同時採用weightSum

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

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:weightSum="2"> 

     <Button 
      android:text="Manage messages" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/bt_messages" 
      android:drawableLeft="@mipmap/ic_message" 
      android:layout_weight="1" /> 

     <Button 
      android:text="Manage activities" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/bt_activities" 
      android:drawableLeft="@mipmap/ic_activities" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</LinearLayout> 
兒童