【发布时间】:2018-05-24 10:00:32
【问题描述】:
我有一个片段,它有一个方形相机(宽度和高度都等于屏幕宽度),在 PercentRelativeLayout 中表示为 FrameLayout。在这个摄像头下面是一个 ImageView,它在单击时拍摄照片。
我想将方形相机垂直居中(因为它已经覆盖了屏幕宽度),然后将 ImageView 在其下方的剩余空间中居中。这是我的 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:id="@+id/llCameraFragment"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<FrameLayout
android:id="@+id/tvCamera"
app:layout_widthPercent="100%"
app:layout_aspectRatio="100%" />
</android.support.percent.PercentRelativeLayout>
<LinearLayout
android:id="@+id/llBelowCamera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:id="@+id/ivCaptureImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/camerashutter" />
</LinearLayout>
</LinearLayout>
问题在于相机视图 (PercentRelativeLayout) 总是从屏幕的最顶部开始。我尝试在 PercentRelativeLayout 中使用 layout_gravity 而不是 gravity,并且还尝试将其包裹在 LinearLayout 周围,并将重力设置为 center / center_vertical。
知道有什么问题吗?感谢任何努力:)
【问题讨论】:
-
您能解释一下您要实现的布局吗?您在 percentLayout 内有一个 100% 宽度的 frameLayout
-
我希望相机视图是一个填充屏幕宽度的正方形。为了让它成为一个正方形,我需要它的高度等于那个宽度。我正在使用 PercentRelativeLayout 来保存相机片段(FrameLayout)
-
我认为在这种情况下你最好使用
ConstraintLayout