的Android - 中心布局
问题描述:
我使用ConstraintLayout的边缘的ImageView的,我想在这样的形象布局的边缘上居中的ImageView: imageview centered的Android - 中心布局
我如何可以通过使用ConstraintLayout不使用海拔达到这一(我不知道如何处理前棒棒糖设备中的高程)。
这是到目前为止我的代码:
<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
app:behavior_hideable="false"
app:behavior_peekHeight="190dp"
android:clickable="true"
android:focusable="true"
android:background="#eee"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:id="@+id/main_ride_finished_container"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/main_driver_enroute_BS_driverImage"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@color/colorPrimary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:elevation="3dp"
/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="35dp"
android:background="#FFFFFF"
>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
答
你可以做的地方使用适当的约束集中在布局边缘的视图。在下面的简单例子中,ImageView
被限制在封闭容器的开始和结束处,以使其水平居中。图像视图的顶部和底部被限制在内部布局的底部以中心在底部。这是ConstraintLayout
如何处理“不可能”的约束。请参阅doc。
<android.support.constraint.ConstraintLayout 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.support.constraint.ConstraintLayout
android:id="@+id/innerLayout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/colorPrimary" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="@id/innerLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/innerLayout" />
</android.support.constraint.ConstraintLayout>
尝试到目前为止在这里发布的代码 – akhilesh0707
@ akhilesh0707我加入了代码示例我正在全光照 – ZeroOne
什么[这](http://saulmm.github.io/mastering-coordinator)会导致你[this](https://github.com/saulmm/CoordinatorBehaviorExample/blob/master/app/src/main/res/layout/activity_main.xml) –