0
Android Studio中的預覽是這樣的:約束佈局:按鈕的高度不匹配預覽
按鈕高度看起來很好。
然而,在我的手機在同一頁是這樣的:
按鈕的高度是從我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>
加成
我發現,如果我用我的電話和我朋友的電話一個按鈕大小不正常,而在模擬器上正常運行。
你有沒有嘗試過使用min:Height&max:Height? – zerocool
看來你給'ListViw'一個固定的高度,所以按鈕將剩下的空間作爲它的高度。 – shhp