Android将imageView调整为全屏方向(Android Resize imageView to fullscreen with orientation)

编程入门 行业动态 更新时间:2024-10-28 04:24:23
Android将imageView调整为全屏方向(Android Resize imageView to fullscreen with orientation)

我有一个包含imageview的xml,我希望在点击时,它会调整为LinearLayout的大小,同时考虑到图像的方向。 然后单击一下,默认替换图像。

我的Xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/grey" android:orientation="horizontal" > <ImageButton android:id="@+id/goToDayButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:src="@drawable/ic_btn_find_prev" android:contentDescription="@string/imgbPrev" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.40" android:orientation="vertical" > <TextView android:id="@+id/textNameService" style="@style/txtvServiceName" android:layout_width="match_parent" android:layout_height="48dp" android:text="@string/largetext" android:textSize="20sp" /> </LinearLayout> <ImageButton android:id="@+id/goToNextButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_btn_find_next" android:contentDescription="@string/imgbNext" android:visibility="invisible" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/sentImageView" android:layout_width="match_parent" android:layout_height="0dp" android:layout_margin="2dp" android:layout_weight="1" android:background="@drawable/frame_shadow" android:contentDescription="@string/description" android:scaleType="fitXY" android:src="@drawable/montreal" /> <TextView android:id="@+id/textDescription" style="@style/txtvServiceDescription" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:maxLines="20" android:textSize="20sp" /> <LinearLayout android:id="@+id/pageIndicatorLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:orientation="horizontal" android:paddingBottom="2dp" android:paddingLeft="2dp" android:paddingRight="2dp" android:paddingTop="2dp" > </LinearLayout> </LinearLayout> </LinearLayout>

你能帮我吗?

I have an xml that contains a imageview and I would like that when clicked, it is resized to the size of LinearLayout taking into account the orientation of the image. And then at a click, replace the image by default.

My Xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/grey" android:orientation="horizontal" > <ImageButton android:id="@+id/goToDayButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:src="@drawable/ic_btn_find_prev" android:contentDescription="@string/imgbPrev" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.40" android:orientation="vertical" > <TextView android:id="@+id/textNameService" style="@style/txtvServiceName" android:layout_width="match_parent" android:layout_height="48dp" android:text="@string/largetext" android:textSize="20sp" /> </LinearLayout> <ImageButton android:id="@+id/goToNextButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_btn_find_next" android:contentDescription="@string/imgbNext" android:visibility="invisible" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/sentImageView" android:layout_width="match_parent" android:layout_height="0dp" android:layout_margin="2dp" android:layout_weight="1" android:background="@drawable/frame_shadow" android:contentDescription="@string/description" android:scaleType="fitXY" android:src="@drawable/montreal" /> <TextView android:id="@+id/textDescription" style="@style/txtvServiceDescription" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:maxLines="20" android:textSize="20sp" /> <LinearLayout android:id="@+id/pageIndicatorLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:orientation="horizontal" android:paddingBottom="2dp" android:paddingLeft="2dp" android:paddingRight="2dp" android:paddingTop="2dp" > </LinearLayout> </LinearLayout> </LinearLayout>

Can you help me please?

最满意答案

我想你需要在单击时缩放ImageView,并在再次单击时缩小。 Android已经举了一个例子 。我可能会对你有所帮助。 更新 : 这是DevBytes中类似效果的一个很好的例子。 它在ActivityOptions中使用新的API,可以直接从JellyBean获得,也可以通过support-v4库访问

从该示例中剪切的代码如下:

Intent i = new Intent(HomeActivity.this, DetailActivity.class); i.putExtra(DetailActivity.EXTRA_COLOUR, colour); Bundle b = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); bitmap.eraseColor(colour); b = ActivityOptions.makeThumbnailScaleUpAnimation(view, bitmap, 0, 0).toBundle(); } startActivity(i, b);

I guess you need to zoom ImageView when it is clicked, and zoom out when it is again clicked. Android has given an example on this.I thing that might helpful for you. Updated : Here is a good example of similar effect in DevBytes. It is using new API in ActivityOptions, which is available from JellyBean directly or can be accessed via support-v4 library

The code snipped from that example is here:

Intent i = new Intent(HomeActivity.this, DetailActivity.class); i.putExtra(DetailActivity.EXTRA_COLOUR, colour); Bundle b = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); bitmap.eraseColor(colour); b = ActivityOptions.makeThumbnailScaleUpAnimation(view, bitmap, 0, 0).toBundle(); } startActivity(i, b);

更多推荐

本文发布于:2023-07-26 02:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全屏   方向   imageView   Android   fullscreen

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!