【问题标题】:Android crop ImageView inside parent RelativeLayoutAndroid在父RelativeLayout内裁剪ImageView
【发布时间】:2013-08-20 17:06:48
【问题描述】:

我想知道如何裁剪ImageView,它具有使用固定宽度和高度的缩放背景图像parent

基本上,我希望使用ImageView android:background 缩放图像,然后我想裁剪图像中超出父级范围的部分。

到目前为止,我有这个代码:

<RelativeLayout android:id="@+id/time_foregrd"
    android:layout_width="57px"
    android:layout_height="100px"
    android:layout_marginLeft="100px"
    android:layout_marginTop="285px"
    android:clipChildren="true"
   >
    <ImageView  android:layout_width="57px"
                android:layout_height="338px"
                android:minWidth="57px"
                android:minHeight="338px"
                android:background="@drawable/time_foreground"
                />
</RelativeLayout>

但它不起作用......我做错了什么?

【问题讨论】:

    标签: java android image scale crop


    【解决方案1】:

    好的,我设法做到了。我没有使用RelativeLayout,而是使用了FrameLayout,效果很好。

    代码如下:

    <FrameLayout android:id="@+id/time_foregrd"
        android:layout_width="57px"
        android:layout_height="100px"
        android:layout_marginLeft="100px"
        android:layout_marginTop="285px"
       >
        <ImageView  android:layout_width="57px"
                    android:layout_height="338px"
                    android:layout_gravity="bottom"
                    android:scaleType="fitXY"
                    android:src="@drawable/time_foreground"
                    />
    </FrameLayout>
    

    【讨论】:

    • 使用RelativeLayout时是不是不行?因为我在这个容器里需要不止一个孩子。
    【解决方案2】:

    我可以在我的 RelativeLayout 中使用

    做同样的事情
    android:scaleType="centerCrop"
    

    【讨论】:

      【解决方案3】:

      1- 用 relativeLayout 包装该元素。

      2- 将此添加到您的元素中:android:layout_gravity="center_vertical"

      它将充当 ImageView 的 scaleType="centerCrop"

         <LinearLayout
              android:id="@+id/ll_wrapper"
              android:layout_width="match_parent"
              android:layout_height="250.0dp" >
              <TextureView
                  android:layout_width="match_parent"
                  android:layout_height="451.0dp"
                  android:id="@+id/tv_YourElement"
                  android:layout_gravity="center_vertical" /> 
      
          </LinearLayout>
      

      android:layout_gravity= "center_vertical" , "center_horizo​​ntal", “中心”,...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-06
        • 2018-09-19
        • 1970-01-01
        • 2013-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-18
        相关资源
        最近更新 更多