大佬教程收集整理的这篇文章主要介绍了android – ConstraintLayout View.GONE用法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想到的是如何尽可能优雅地解决这个“谜题”?
@L_419_0@
如您所见,在布局的右侧部分,我有多个左对齐的视图.在最后一行中,有3个视图水平对齐(它们也在彼此之间对齐).
问题是:如果我将第一个View的可见性从该行设置为GONE,则另外两个(在同一行中)按预期向左移动,但下面的那个(垂直对齐中的最后一行)超过该行(因为它consTraintTop属性设置为View设置为GONE的底部.
我能想到的唯一解决方案是使用ViewGroup对这3个视图进行分组,并将约束添加到最后一行View.
我错过了ConsTraintLayout上的一些属性,这对我的情况有帮助吗?如果在GONE View中设置其中一个,可能会出现某种后退(或多个)约束?
对不起,如果我的解释看起来很深奥,也许图片会帮助你更多:)
LE:增加了布局:https://gist.github.com/DoruAdryan/7e7920a783f07b865489b1af0d933570
<android.support.consTraint.ConsTraintLayout xmlns:android="http://scheR_269_11845@as.android.com/apk/res/android" xmlns:app="http://scheR_269_11845@as.android.com/apk/res-auto" xmlns:tools="http://scheR_269_11845@as.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.AppCompatImageView android:id="@+id/iv_item_small_product_image" android:layout_width="113dp" android:layout_height="113dp" android:layout_marginLeft="7dp" android:layout_marginStart="7dp" android:BACkground="@android:drawable/btn_radio" app:layout_consTraintBottom_toBottomOf="parent" app:layout_consTraintLeft_toLeftOf="parent" app:layout_consTraintStart_toStartOf="parent" app:layout_consTraintTop_toTopOf="parent" /> <android.support.v7.widget.AppCompatImageView android:id="@+id/iv_row_1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:BACkground="@android:drawable/bottom_bar" app:layout_consTraintLeft_toRightOf="@+id/iv_item_small_product_image" app:layout_consTraintright_toRightOf="parent" app:layout_consTraintTop_toTopOf="parent" /> <ro.emag.android.views.FontTextView android:id="@+id/tv_row_2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="3dp" android:ellipsize="end" android:maxLines="2" app:layout_consTraintLeft_toRightOf="@+id/iv_item_small_product_image" app:layout_consTraintright_toRightOf="parent" app:layout_consTraintTop_toBottomOf="@+id/iv_row_1" app:layout_goneMarginTop="0dp" tools:text="Some text long enough to be split on multiple lines on some devices." /> <android.support.v7.widget.AppCompatratingBar android:id="@+id/rb_row_3_1" style="@style/Widget.AppCompat.ratingBar.small" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="9dp" android:isInDicator="true" android:numStars="5" android:stepSize="0.1" app:layout_consTraintLeft_toRightOf="@+id/iv_item_small_product_image" app:layout_consTraintTop_toBottomOf="@id/tv_row_2" /> <TextView android:id="@+id/tv_row_3_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:layout_marginStart="6dp" android:layout_marginTop="9dp" app:layout_consTraintLeft_toRightOf="@+id/rb_row_3_1" app:layout_consTraintTop_toBottomOf="@id/tv_row_2" tools:text="106" /> <TextView android:id="@+id/tv_row_3_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:layout_marginStart="6dp" android:layout_marginTop="9dp" app:layout_consTraintLeft_toRightOf="@+id/tv_row_3_2" app:layout_consTraintright_toRightOf="parent" app:layout_consTraintTop_toBottomOf="@id/tv_row_2" app:layout_goneMarginLeft="0dp" app:layout_goneMarginStart="0dp" tools:text="Options available" /> <android.support.consTraint.barrier android:id="@+id/barrier" android:layout_width="wrap_content" android:layout_height="wrap_content" app:barrierDirection="bottom" app:consTraint_referenced_ids="rb_row_3_1,tv_row_3_2,tv_row_3_3" /> <TextView android:id="@+id/tv_row_4" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="3dp" android:ellipsize="end" android:maxLines="1" app:layout_consTraintLeft_toRightOf="@+id/iv_item_small_product_image" app:layout_consTraintright_toRightOf="parent" app:layout_consTraintTop_toBottomOf="@+id/barrier" tools:text="Some text on last row" /> </android.support.consTraint.ConsTraintLayout>
现在,最后一行取决于屏障而不是第三行的其中一个视图.由于障碍取决于第二行的三个视图,因此您不会出现边缘问题.
另外,我注意到你不需要指南.右段可以直接依赖于imageview.
如果你不熟悉障碍,这里有一个link来帮助你.
由于此功能仅在ConsTraintLayout的1.1.0 beta1版本中可用,因此不要忘记将此行添加到build.gradle文件中.
compile 'com.android.support.consTraint:consTraint-layout:1.1.0-beta1'
以上是大佬教程为你收集整理的android – ConstraintLayout View.GONE用法全部内容,希望文章能够帮你解决android – ConstraintLayout View.GONE用法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。