【问题标题】:Overlap images if there is not enough space to show them如果没有足够的空间显示它们,则重叠图像
【发布时间】:2014-10-01 23:47:15
【问题描述】:

我正在编写一个小纸牌游戏,其中用户有五张卡片,它们应位于屏幕左侧。假设每张卡片的宽度设置为 100dp。然后我希望卡片被相应地裁剪并放在彼此下方。如果卡片的总高度太大而无法全部显示,我希望它们重叠,而不是让它们变得更小。

例如,左边可能是平板电脑,空间足够,右边是智能手机,我希望卡片重叠。

有什么想法可以做到这一点吗?

【问题讨论】:

    标签: android imageview


    【解决方案1】:

    您可以计算图像视图的高度,然后像这样裁剪卡片图像:

    bm = Bitmap.createBitmap(originalbitmap, 0, 0, fullViewWidth, calculatedViewHeight);
    imageview.setImageBitmap(bm);
    

    【讨论】:

      【解决方案2】:

      我搞定了:

      代码

      public class HandCardsLayout extends RelativeLayout {
      
        // constructors etc..
      
        public void init() {
            Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            int heightLandscape = size.y;
            int viewDistance = heightLandscape / 5;
            for (int i = 0; i < 5; i++) {
                ImageView imageView = getImageViewAt(i);
                if(i < 4) {
                    imageView.setPadding(0, 0, 0, -viewDistance);
                }
            }
        }
      }
      

      布局文件

      <de.memorian.HandCardsLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:background="@android:color/transparent"
          android:gravity="center"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
          <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:scaleType="centerInside"
              android:adjustViewBounds="true"
              android:layout_above="@+id/handCard2"
              android:id="@+id/handCard1"/>
      
          <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:scaleType="centerInside"
              android:adjustViewBounds="true"
              android:layout_above="@+id/handCard3"
              android:id="@+id/handCard2" />
      
          <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:scaleType="centerInside"
              android:adjustViewBounds="true"
              android:layout_above="@+id/handCard4"
              android:id="@+id/handCard3" />
      
          <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:scaleType="centerInside"
              android:adjustViewBounds="true"
              android:layout_above="@+id/handCard5"
              android:id="@+id/handCard4" />
      
          <ImageView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:scaleType="centerInside"
              android:adjustViewBounds="true"
              android:layout_alignParentBottom="true"
              android:id="@+id/handCard5" />
      </de.memorian.HandCardsLayout>
      

      这个 sn-p 以均匀的距离与 ImageView 重叠。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-15
        • 1970-01-01
        • 1970-01-01
        • 2014-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-21
        相关资源
        最近更新 更多