我刚刚创建了一个简单的layout.xml,我希望在这个布局中添加一个约束布局,以便通过拖放轻松管理视图如何解决这个问题
............................................... .................
这是我的layout.xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/menuRL"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="#bebdbd">
<TextView
android:id="@+id/itemNameShowOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/itemImage"
android:layout_toEndOf="@+id/itemImage"
android:text="TextView"
android:textSize="10dp"
android:textStyle="bold" />
<RelativeLayout
android:id="@+id/showOrderqtyID"
android:layout_width="60dp"
android:layout_height="fill_parent"
android:background="#f9762f"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="82dp">
<TextView
android:id="@+id/txtQTYshowOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="30dp"
android:layout_centerVertical="true"
android:text="0" />
</RelativeLayout>
<TextView
android:text="TotalPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="34dp"
android:id="@+id/textView7"
android:layout_alignBaseline="@+id/itemNameShowOrder"
android:layout_alignBottom="@+id/itemNameShowOrder"
android:layout_alignParentEnd="true" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:textStyle="bold"
android:textSize="25dp"
android:layout_height="wrap_content"
android:id="@+id/tpID"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/textView7" />
</RelativeLayout>
</LinearLayout>
答案 0 :(得分:1)
首先将依赖项添加到您的gradle:
compile 'com.android.support.constraint:constraint-layout:1.0.1'
然后您可以将其添加到Layout.xml中,如下所示:
<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="wrap_content"
android:layout_marginTop="2dp"
android:clickable="true"
android:focusable="true"
android:background="@drawable/border_bottom">
<!-- your view here -->
</android.support.constraint.ConstraintLayout>
答案 1 :(得分:1)