java - 可缩放的 FrameLayout 获得了绝对宽度和高度,但其中的视图与这些尺寸不匹配
问题描述
好的,大家好。
我对应用程序开发很陌生。
介绍:
在我的应用程序中,我使用RelativeLayout进行活动。在这个布局中,我有可缩放的 FrameLayout。在这个布局中,我必须只有一个布局。在我的情况下,它是另一个RelativeLayout。最后在这个布局中,我有一些ImageView。此活动的目的是通过开关显示地图层(drawables )。
代码在这里:
<?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:background="@color/colorDarkBlueGrey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.example.cotwcompanion.ZoomableView
android:id="@+id/zoomView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/mapLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/mapBCG"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:contentDescription="@string/map_name"/>
<!-- Here I generate other ImageViews with 'same' attributes -->
</RelativeLayout>
</com.example.cotwcompanion.ZoomableView>
<!-- Here are other layouts -->
</RelativeLayout>
问题:
我的问题或多或少是视觉上的。我想将这些层(1:1 的比例)显示为显示器允许的(垂直)。因此我需要重叠显示的宽度。
我需要它看起来像什么: 图像
我试过的:
- 我认为 FrameLayout 会做到这一点。所以我尝试以编程方式设置它的宽度 和高度,所以它适合屏幕高度并具有相同的宽度,因为前面提到了 1:1 的比例。如果我尝试记录这些维度,似乎一切都已设置好。由于ImageView及其父RelativeLayout中的match_parent属性,因此它应该做其他所有事情并拉伸这些视图以填充FrameLayout。但一切都只适合屏幕宽度。 此处的结果图片:IMAGE
代码在这里:
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(height, height);
FrameLayout frame = findViewById(R.id.zoomView);
frame.setLayoutParams(lp);
- 我尝试了与普通FrameLayout相同的方法,但得到了相同的结果。
- 我还尝试将FrameLayout与 Horizo ntalScrollView和自定义可缩放 ImageView交换。这或多或少地工作得很好,但问题是当我缩放地图时。水平滚动会破坏缩放地图的每一个动作。因此,我尝试使用禁用滚动的方法创建自定义 Horizo ntalScrollView。即使我从ImageView捕捉到缩放状态 并将滚动设置为notEnabled,它仍然无法正常工作。
你去吧。就像我说的缩放方法和其他所有方法一样。我只需要以某种方式拥有比显示允许的更大的视图。
编辑 [21.11.2020]:
因此,正如 Daxi建议的那样,我尝试将ZoomableLayout中的RelativeLayout更改为ConstraintLayout。我还将ZoomableLayout更改为从ConstraintLayout扩展。这几乎解决了我的问题。但是我无法左右滚动。我只能放大。所以我采用了我最后一次尝试的解决方案之一,并用HorizontalScrollView包装了ZoomableView。一切似乎都很好。但是,我现在无法滚动到ImageView的“开始”或“结束” 。好像我只能在 HorizontalScrollView 的基本宽度内滚动而不是ImageView的宽度。所以我现在需要解决这个问题。
代码在这里:
<RelativeLayout>
<HorizontalScrollView>
<ZoomableView extends ConstraintLayout>
<ConstraintLayout>
<ImageView/>
.
.
</ConstraintLayout>
</ZoomableView>
</HorizontalScrollView>
.
.
</RelativeLayout>
如果这与stackoverflow上已经描述的其他问题重复,我很抱歉,但我现在搜索了两天以上的解决方案,但仍然没有找到任何解决方案。也许我是不好的发现者。如果是这种情况,请随时告诉我。如果需要,我会删除它。
如果会有一些非常好的答案和解决方案,我将不胜感激。谢谢你。
解决方案
你会考虑使用ConstraintLayouts吗?如果是,您可以像这样使用它
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mapLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/mapBCG"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/map_name"/>
<!-- Here I generate other ImageViews with 'same' attributes -->
</androidx.constraintlayout.widget.ConstraintLayout>
但是,我不确定这将如何与您的 ZoomableView 交互
推荐阅读
- r - 从多运行文件中提取一个变量
- odoo-11 - Tour 在 odoo 中是如何工作的
- flutter - 更新已创建的颤振项目中的组织
- apache-zookeeper - SchedulerStateManagerAdaptor 无法从 Heron 集群中的 zookeeper 路径获取数据
- python-3.x - python中的Apache Storm命令行客户端
- apache - 如何通过htaccess将所有页面重定向到同一服务器上的一个页面?
- html - 如何删除两个单词之间的大空间以证明移动设备中的对齐?
- ibeacon - 使用 Apple Wallet 当 iBeacon 触手可及时的自定义操作
- extjs - Extjs 5.0.1:当我们将边框半径赋予网格或其任何父级时,在滚动时获取网格中的空白
- c# - 如何从通用列表转换
加倍[]?