2016-11-16 69 views
0

Android Studio中的预览是这样的:约束布局:按钮的高度不匹配预览

enter image description here

按钮高度看起来很好。

然而,在我的手机在同一页是这样的:

enter image description here

按钮的高度是从我Android Studio中预览看到不同。为什么?

这里是XML:

activity_chat.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    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" 
    android:fitsSystemWindows="true" 
    tools:context="ocm.my.chat.View.ChatActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     > 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/chat_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      android:title="fsdasdfsda" 
      android:layout_weight="1"/> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_chat"/> 


</android.support.design.widget.CoordinatorLayout> 

content_chat.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 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" 
              app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    > 


    <EditText 
     android:id="@+id/msg_type" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="8dp" 
     android:hint="Input message" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/btn_chat_send" 
     app:layout_constraintTop_toBottomOf="@+id/list_msg" 
     tools:layout_constraintBottom_creator="1" 
     tools:layout_constraintLeft_creator="1" 
     tools:layout_constraintRight_creator="1" 
     tools:layout_constraintTop_creator="1"/> 

    <Button 
     android:id="@+id/btn_chat_send" 
     android:layout_height="0dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginTop="8dp" 
     android:background="@color/background_floating_material_dark" 
     android:text="Send" 
     android:textColor="@color/background_material_light" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/list_msg" 
     tools:layout_conversion_absoluteHeight="47dp" 
     tools:layout_conversion_absoluteWidth="106dp" 
     tools:layout_conversion_absoluteX="262dp" 
     tools:layout_conversion_absoluteY="447dp" 
     android:layout_width="106dp"/> 

    <ListView 
     android:id="@+id/list_msg" 
     android:layout_width="0dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="8dp" 
     android:divider="@null" 
     android:listSelector="@android:color/transparent" 
     android:transcriptMode="alwaysScroll" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     tools:layout_constraintLeft_creator="1" 
     tools:layout_constraintRight_creator="1" 
     android:layout_height="450dp"/> 

</android.support.constraint.ConstraintLayout> 

加成


我发现,如果我用我的电话和我朋友的电话一个按钮大小不正常,而在模拟器上正常运行。

+0

你有没有尝试过使用min:Height&max:Height? – zerocool

+0

看来你给'ListViw'一个固定的高度,所以按钮将剩下的空间作为它的高度。 – shhp

回答

0

ListView的高度已修复,Button的高度取决于ListView的高度。所以在不同的屏幕上它将显示不同。