我想将View的左侧和右侧约束到它的父视图的边距,并使其填充分配的空间.但是,将宽度设置为match_parent或者wrap_content似乎产生相同的结果.
有没有相当于match_constraints的东西(而不是match_parent和wrap_content)?难道match_parent和wrap_content影响布局还是他们在新的约束布局忽略?
爱我最喜欢的平台的新布局系统!
我需要帮助ConstraintSet.我的目标是在代码中更改视图的约束,但我无法弄清楚如何正确执行此操作.
我有4 TextView秒和1个ImageView.我需要为ImageView其中一个设置约束TextView.
check_answer4 = (TextView) findViewById(R.id.check_answer4);
check_answer1 = (TextView) findViewById(R.id.check_answer1);
check_answer2 = (TextView) findViewById(R.id.check_answer2);
check_answer3 = (TextView) findViewById(R.id.check_answer3);
correct_answer_icon = (ImageView) findViewById(R.id.correct_answer_icon);
Run Code Online (Sandbox Code Playgroud)
如果第一个答案是正确的,我需要设置的限制ImageView,以
app:layout_constraintRight_toRightOf="@+id/check_answer1"
app:layout_constraintTop_toTopOf="@+id/check_answer1"
Run Code Online (Sandbox Code Playgroud)
如果第二个答案是正确的,我需要设置的限制ImageView,以
app:layout_constraintRight_toRightOf="@+id/check_answer2"
app:layout_constraintTop_toTopOf="@+id/check_answer2"
Run Code Online (Sandbox Code Playgroud)
等等.
android android-layout android-view android-constraintlayout
如何在约束布局中垂直对齐和居中对象?可以垂直或水平对齐,但除了限制两个网格线之间的视图之外,我还没有找到同时居中的方法.
似乎居中是约束布局的一个巨大问题,迫使我回到"centerInParent","centerVertical"和"centerHorizontal"的相对布局.
不幸的是,我发现不使用两个网格线的唯一方法是使用嵌套的Relative和LinearLayouts(Constraint Layout应该解决这个确切的场景!).
使用相对和线性布局的布局:
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintTop_toBottomOf="@id/user_points"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<LinearLayout
android:id="@+id/stat_1_layout"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/divider_1"
android:orientation="vertical">
<TextView
android:id="@+id/stat_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="10"
android:textSize="16dp"
android:textColor="@color/textSecondaryDark"
android:maxLines="1"/>
<TextView
android:id="@+id/stat_detail_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Streak"
android:textSize="8sp"
android:textColor="@color/textSecondary"
android:maxLines="1"/>
</LinearLayout>
<View
android:id="@+id/divider_1"
android:layout_width="1dp"
android:layout_height="38dp"
android:layout_toLeftOf="@+id/stat_2_layout"
android:background="@drawable/linedivider"/>
<LinearLayout
android:id="@+id/stat_2_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginRight="18dp"
android:layout_centerInParent="true"
android:orientation="vertical">
<TextView
android:id="@+id/stat_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="243"
android:textSize="16dp"
android:textColor="@color/textSecondaryDark"
android:maxLines="1"/>
<TextView
android:id="@+id/stat_detail_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Calories Burned"
android:textSize="8sp"
android:textColor="@color/textSecondary"
android:maxLines="1"/>
</LinearLayout> …Run Code Online (Sandbox Code Playgroud) 最近试图实施,Constraint Layout但我发现Barrier和Guideline工作相同.两者都像分频器.它们之间有什么区别吗?
考虑以下布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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.support.constraint.ConstraintLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#0000FF"
android:padding="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintDimensionRatio="H,3:1"
tools:layout_editor_absoluteX="16dp" />
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我不确定app:layout_constraintDimensionRatio是如何工作的.我的理解是比例总是宽度:高度.因此3:1将始终使ImageView看起来比高度宽3倍.前缀H或W告诉ConstraintLayout哪个维度应该尊重比率.如果是H则表示首先根据其他约束计算宽度,然后根据纵横比调整高度.然而,这是布局的结果:
高度是宽度的3倍,这是意料之外的.任何人都可以向我解释如何计算尺寸相对于app:layout_constraintDimensionRatio设置?
android scale aspect-ratio android-layout android-constraintlayout
我有两个标题视图,HeaderViewA和HeaderViewB.这些视图可以具有任何可见性visible或组合gone.
我需要BigView被定位在了最低的任一HeaderViewA/ HeaderViewB.
这可能没有嵌套ConstraintLayout吗?
android android-layout android-support-library android-constraintlayout
谷歌已经宣布了一种名为" ConstraintLayout " 的新布局,它应该是最终布局,可以在保持平坦(没有嵌套布局)的同时取代所有布局,并且具有更好的性能.
事情是,我几乎没有看到任何可以帮助我解决这个问题的教程,除了在Google IO上展示的视频.
我想要做的是,假设我在另一个布局中有一个垂直居中的LinearLayout - 将它们转换为单个ConstraintLayout.
毕竟,这是这个新布局的目的......
我想要处理的布局如下:
请注意,中心的视图仅垂直居中,并且2个textView位于ImageView的右侧,ImageView也垂直居中.
这一切都适用于RelativeLayout,它具有2个TextViews的LinearLayout,但我想知道如何将它们转换为单个ConstraintLayout.
这是我展示的示例XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:minHeight="?attr/listPreferredItemHeightSmall">
<ImageView
android:id="@+id/appIconImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="4dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="4dp"
android:layout_marginStart="2dp"
android:adjustViewBounds="true"
android:src="@android:drawable/sym_def_app_icon"
tools:ignore="ContentDescription"/>
<LinearLayout
android:id="@+id/appDetailsContainer"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/appIconImageView"
android:layout_toLeftOf="@+id/overflowView"
android:layout_toRightOf="@+id/appIconImageView"
android:layout_toStartOf="@+id/overflowView"
android:orientation="vertical">
<TextView
android:id="@+id/appLabelTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:text="label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textDirection="locale"
tools:ignore="HardcodedText,UnusedAttribute"/>
<TextView
android:id="@+id/appDescriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:minLines="3"
android:text="description"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textDirection="locale"
tools:ignore="HardcodedText,UnusedAttribute"/>
</LinearLayout>
<ImageView
android:id="@+id/overflowView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:background="?attr/selectableItemBackground"
android:clickable="true" …Run Code Online (Sandbox Code Playgroud) 要实现什么:ConstraintLayout或者CoordinatorLayout在android中进行适当的材料设计?
android material-design coordinator-layout android-constraintlayout
当我尝试ConstraintLayout在我的布局中使用时content_main.xml,我收到以下消息:
使用约束库的版本1.0.0-alpha5,这是过时的
我目前正在使用以下库依赖项:
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha5'
Run Code Online (Sandbox Code Playgroud)
如何获取约束布局的最新版本号?
我有最新的Android Studio(2.3 beta 3),看起来ConstraintLayout是创建项目时的默认设置.如何让Android Studio使用RelativeLayout作为新项目的默认布局元素?
android android-studio android-relativelayout android-constraintlayout