线性布局中的约束布局模拟器和IDE之间的预览不同吗? [英] Constraintlayout in linearLayout different preview between emulator and IDE?
本文介绍了线性布局中的约束布局模拟器和IDE之间的预览不同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在代码中实现 ContstraintLayout
,但是问题是为什么当我在模拟器和IDE中运行它时,为什么会有不同?对于信息,我在 LinearLayout
Vertical中放置了 ConstraintLayout
.这是我的XML代码:
I am trying to implement a ContstraintLayout
in my code, but the problem is why there is different when I run it on the emulator and in the IDE?
for the info, I put ConstraintLayout
in LinearLayout
Vertical.
and here my XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"
tools:context="navotera.syasep.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="170dp"
>
<RelativeLayout
android:id="@+id/topBorder"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/holo_red_light">
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitCenter"
android:foregroundGravity="right"
android:src="@mipmap/profile"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.99"
android:id="@+id/imageView3"
app:layout_constraintVertical_bias="0.25"
android:paddingLeft="270dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingLeft="18dp"
android:paddingTop="10dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:textSize="@dimen/text_big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nama"
android:text="Hendra" />
<TextView
android:textSize="@dimen/text_big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nim"
android:text="nim" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foregroundGravity="right">
<TextView
android:textSize="@dimen/text_bigger"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/semester"
android:text="7"
android:layout_weight="1"
android:layout_marginEnd="184dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="184dp"
app:layout_constraintTop_toBottomOf="@+id/tsemester" />
<TextView
android:text="IPK"
android:textSize="@dimen/text_small"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:id="@+id/tipk"
android:textColor="@color/colorAccent"
android:layout_weight="1"
tools:layout_editor_absoluteY="28dp"
app:layout_constraintRight_toLeftOf="@+id/tsemester"
android:layout_marginEnd="48dp"
android:layout_marginRight="48dp"
app:layout_constraintLeft_toLeftOf="@+id/ipk" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ipk"
android:text="3.99"
android:textSize="@dimen/text_bigger"
android:layout_weight="1"
tools:layout_editor_absoluteY="49dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
app:layout_constraintRight_toLeftOf="@+id/semester"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.14" />
<TextView
android:text="Semester"
android:textSize="@dimen/text_small"
android:layout_width="94dp"
android:layout_height="wrap_content"
android:id="@+id/tsemester"
android:textColor="@color/colorAccent"
android:layout_weight="1"
tools:layout_editor_absoluteY="28dp"
tools:layout_editor_absoluteX="156dp" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</RelativeLayout>
<android.support.constraint.ConstraintLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.constraint.ConstraintLayout>
<TextView
android:text="Jadwal / Kehadiran"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingLeft="13dp"
android:id="@+id/tkehadiran"
android:textSize="@dimen/text_medium" />
</LinearLayout>
</RelativeLayout>
感谢您的任何建议.
推荐答案
如果使用ConstraintLayout,则将所有视图作为ConstraintLayout的直接子元素,例如
if using ConstraintLayout, then put all the views as a direct child of the ConstraintLayout, like this
<?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"
android:orientation="vertical">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button" android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent" android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="16dp"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2" app:layout_constraintRight_toLeftOf="@+id/button"
app:layout_constraintBottom_toTopOf="@+id/button" android:layout_marginBottom="16dp"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
app:layout_constraintLeft_toRightOf="@+id/button"
app:layout_constraintBottom_toTopOf="@+id/button" android:layout_marginBottom="16dp"/>
<RadioButton
android:text="RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" tools:layout_editor_absoluteY="376dp"
android:id="@+id/radioButton"
app:layout_constraintRight_toLeftOf="@+id/button"/>
<QuickContactBadge
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:srcCompat="@mipmap/star_empty"
android:id="@+id/quickContactBadge" android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent" android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent" android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>`
这篇关于线性布局中的约束布局模拟器和IDE之间的预览不同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文