【问题标题】:Using ImageView as Parent?使用 ImageView 作为父级?
【发布时间】:2016-09-21 05:36:15
【问题描述】:

是否可以使用ImageView 作为父母?我想在ImageView 上放几个TextViews,当用户放大ImageView 时,我也想放大TextViews!

注意:我制作了可缩放的 ImageView,但无法制作可缩放的 RelativeLayout...

编辑:

我的 xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

    <nikdan.m.metro.ZoomableImageView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/imgMap"
         android:layout_gravity="center" />

    <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:text="Hello"
         android:id="@+id/text"
         android:layout_gravity="center"
         android:textColor="#ff0000" />
</FrameLayout>

【问题讨论】:

  • 应该可以使用setScaleXsetScaleYsetPivotX、setPivotY`来制作可缩放视图。但我不希望 stackoverflow 上的任何人都能为您提供可以使用的代码。
  • 如果 TextView 的内容没有改变,你可以通过注册一个全局预绘制监听器使图像 ZoomableImageView 成为 framelayout 的缓存视图位图来作弊

标签: android android-studio


【解决方案1】:

FrameLayout 设为Parent,并在ImageView 之后添加TextViews。

这应该可以解决问题。

【讨论】:

  • 谢谢。我不知道 FrameLayout 是如何工作的。我想我应该学习!
  • 感谢您注意到:)
  • 我做到了,但仍然无法正常工作。 ImageView 缩放,但 TextView 没有!
  • 从未亲自尝试过,但试试这个stackoverflow.com/questions/4167593/…
猜你喜欢
  • 2012-07-15
  • 1970-01-01
  • 1970-01-01
  • 2015-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多