2016-10-09 14 views
0

有我的布局代码:安卓:观设计预览并不像真正的

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:layout_width="119dp" 
     android:layout_height="84dp" 
     android:src="@drawable/image_template" 
     android:id="@+id/roleIco" 
     android:scaleType="fitCenter" 
     android:layout_marginBottom="16dp" 
     android:layout_marginTop="16dp" /> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="the name of the player" 
     android:id="@+id/playerName" 
     android:textAppearance="@style/TextAppearance.AppCompat.Body2" 
     android:layout_marginTop="16dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginEnd="16dp" 
     android:layout_marginRight="16dp" /> 

     <TextView 
      android:text="Role name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/roleName" 
      android:textAppearance="@style/TextAppearance.AppCompat.Body1" 
      android:layout_marginTop="16dp" /> 

     <TextView 
      android:text="Fraction" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/fractionName" 
      android:layout_marginTop="16dp" 
      android:textAppearance="@style/TextAppearance.AppCompat.Subhead" /> 

    </LinearLayout> 

    <ImageView 
     android:layout_width="74dp" 
     android:layout_height="match_parent" 
     android:src="@drawable/icon_heart" 
     android:id="@+id/playerStatusIcon" 
     android:scaleType="fitCenter" /> 


</LinearLayout> 

而问题是,在Android Studio中设计预览它看起来像这样: See this image, please

但是,当我在手机上启动这个程序,它看起来像这样:

See this image, please

有人能够帮助我这种差异的原因是什么,以及如何消除它,并在预览中将真实的视图变成这样?

感谢答案,因为你是根据API等级24看到预览,而你的附实装置的图像低于API级别21

+0

你指的是预览中的文字颜色? – Sanjeet

+0

您尚未设置父线性布局的方向。尝试将其方向设置为“水平”。 –

+0

@Vaibhav Agarwal默认方向始终是水平的,即使你没有定义它 –

回答

0

预览是不同的。

因此,有没有材料设计可用在您的真实设备,因此是有区别的。 在运行Android棒棒糖或更高版本的真实设备中尝试它您将获得相同的结果。