2017-06-05 59 views
0

出現,這是佈局的XML文件的代碼:Android的 - 佈局不會在設備上,因爲它出現在預覽

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.barda.wikirace.MainActivity" 
    android:background="@drawable/backgroundmain" 
    android:orientation="vertical" 
    android:weightSum="1" 
    android:id="@+id/activity_main" 
    > 


    <ImageView 
     android:id="@+id/wikiRaceTop" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:background="@android:color/transparent" 
     app:srcCompat="@drawable/wikiracetop" /> 

    <TextView 
     android:id="@+id/emptyView" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="1" 
     > 
     <View 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.25"/> 

     <Button 
      android:layout_marginBottom="7dp" 
      android:id="@+id/twoPlayersBtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/twoplayersbutton" 
      /> 

     <View 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.5"/> 




     <Button 
      android:layout_marginBottom="7dp" 
      android:id="@+id/singlePlayerBtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/playbutton" 
      android:onClick="startSinglePlayerMenuActivity"/> 
     <View 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.25"/> 



    </LinearLayout> 


</LinearLayout> 

這是它的外觀預覽:enter image description here

,這是它如何出現在設備上(LG G4): enter image description here

什麼會導致問題?正如你所看到的,我希望按鈕對他們來說是正確的顏色。

回答

0

爲什麼不只是使用約束佈局? 如果你想以你的方式做它,你將不得不爲固定值或match_parent設置寬度爲什麼?因爲當你說wrap_content和圖像是大的將會在其他視圖正在發生的情況下也可以爲按鈕設置一個android:layout_weight如果你想使用權重作爲「控制」你的佈局,與您用來調整視圖的方法。

相關問題