当我尝试在按钮单击时设置组的可见性时,它不会影响视图的可见性.使用com.android.support.constraint:constraint-layout:1.1.0-beta4.我已经尝试过没有问题地设置元素,但是没有成功.
我的MainActivity.kt
private fun toggleLoginUI(show: Boolean) {
if (show) {
group.visibility = VISIBLE
} else {
group.visibility = INVISIBLE
}
}
fun onClick(view: View) {
when (view.id) {
R.id.button -> toggleLoginUI(true)
R.id.button4 -> toggleLoginUI(false)
}
}
Run Code Online (Sandbox Code Playgroud)
我的activity_main.xml
<android.support.constraint.ConstraintLayout..
<TextView
android:id="@+id/textView"
... />
<TextView
android:id="@+id/textView2"
... />
<Button
android:id="@+id/button"
.../>
<Button
android:id="@+id/button4"
... />
<android.support.constraint.Group
android:id="@+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:constraint_referenced_ids="textView,textView2" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) android kotlin kotlin-android-extensions android-constraintlayout
我需要对一组视图应用一些约束ConstraintLayout.我想将这些视图分组并继续编辑,而Android Studio中的布局设计器将它们视为单个视图.有没有办法这样做而不用ViewGroup(另一种布局)实际包装视图?如果需要这样的包装器,可能会有一个包装器布局,ConstraintLayout并允许对对象进行分组而不会创建像RelativeLayout?
android android-studio android-constraintlayout constraint-layout-chains
为什么RelativeLayout替换为ConstraintLayoutandroid空活动的默认布局文件.我需要知道为什么要使用ConstraintLayout它,它为我们提供了什么其他好处.
我在ConstrainLayout中有一个视图如下.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="260dp"
android:textColor="#FFF"
android:textSize="16sp"
app:layout_constraintLeft_toLeftOf="@+id/parent"
app:layout_constraintTop_toBottomOf="@id/message_date"
android:id="@+id/text_main"
/>
Run Code Online (Sandbox Code Playgroud)
我想根据某些条件将视图更改为app:layout_constraintLeft_toLeftOf="@+id/parent"或layout_constraintLeft_toRightOf="@+id/parent"在recycleViewHolder中以编程方式.
每当我创建类似Button和TextView中的视图时ConstraintLayout,它们都会卡在顶角而不是我放置的位置.
我尝试创建新活动并更改模拟器,但结果仍然相同.
这是正在发生的事情的屏幕截图:
可能是什么问题?
android android-layout android-view view-hierarchy android-constraintlayout
我的表格大约有12/13个字段.我Scrollview在约束布局中使用了一个内部.下面是XML布局的层次结构.问题是,它不会滚动到底部而是仅滚动到前10个初始视图.最后3个字段被隐藏,因为视图不再滚动.
父母布局
<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:id="@+id/activity_register"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical">
<!-- Textview and a button -->
<ScrollView
android:id="@+id/scrollView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:overScrollMode="never"
android:scrollbars="none"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Child Views (12/13 views of the fields)-->
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) android constraints scrollview android-layout android-constraintlayout
我在使用标签<include>和<merge>ConstraintLayout内部时遇到问题.
我想创建一个平面视图层次结构(因此Constraints),但仍然有可重用的元素.所以我<include>在我的布局和<merge>包含的布局中使用以避免嵌套布局(特别是避免嵌套的ConstraintLayouts)
所以我写了这样的:父布局
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/review_1"
layout="@layout/view_movie_note"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/review_2"/>
<include
layout="@layout/view_movie_note"
android:id="@+id/review_2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="7dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/review_1"
app:layout_constraintRight_toRightOf="parent"
/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这个view_movie_note:
<merge>
<TextView
android:id="@+id/note_origin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginStart="5dp"
app:layout_constraintStart_toStartOf="@+id/cardView2"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="5dp" />
<android.support.v7.widget.CardView
android:id="@+id/five_star_view_container"
android:layout_width="0dp"
android:layout_height="52dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="10dp"
android:elevation="3dp"
app:cardUseCompatPadding="true"
app:contentPaddingTop="22dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_min="52dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/note_origin">
<FiveStarsView
android:id="@+id/five_star_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cardView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:cardBackgroundColor="@color/colorPrimary"
app:contentPaddingLeft="15dp"
app:contentPaddingRight="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/note_origin">
<TextView
android:id="@+id/grade" …Run Code Online (Sandbox Code Playgroud) ConstraintLayout只要在他的右边有另一个视图的空间,是否有可能让视图增长?
用例是除了彼此之外还有一个value和unitTextViews.该valueTextView的应该可以,只要有空间的成长unit.如果没有足够的空间,value应该切割.
我用链子和其他一些东西尝试过但是无法完成它.在value不停止生长,然后unit再是不可见的.这是当前的代码:
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:lines="1"
app:layout_constraintBaseline_toBaselineOf="@+id/unit"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/unit"
tools:text="12533939532" />
<TextView
android:id="@+id/unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toRightOf="@id/value"
app:layout_constraintRight_toRightOf="parent"
tools:text="km" />
Run Code Online (Sandbox Code Playgroud) 在我的布局中,我有2个textview水平相同的重量和约束布局,但我希望那些textview具有不同重量的6:4比例.
那么如何使用约束布局在我的布局中实现这一点.
我对 Android 开发相当陌生,今天我想知道“ConstraintLayout”中的“垂直偏差”和“水平偏差”分别有何用途。