如何旋转视图也通过协调的Android [英] How to rotate view by coordinate also in Android
本文介绍了如何旋转视图也通过协调的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先了解我的问题投票前正常,
first understand my question properly before voting,
我认为像
<View
android:id="@+id/View01"
android:layout_width="280dp"
android:layout_height="150dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:layout_marginTop="83dp"
android:background="#212121"
android:rotation="-5"
android:visibility="visible" />
和输出,
您可以看到,当我使用的android:旋转= - 5,其旋转视图(黑匣子),但它们的坐标保持不变(蓝色矩形)
you can see that when i use android:rotation="-5", it rotate views(black box) but their coordinates remains same (blue rectangle).
我想旋转后使用新的矩形,但我没有这样做,我读到的 Rect.mapPoint ,但仍然未能达到目标,因为这帮助吗?
i want to use new Rect after rotation but i fails to do so, i read about Rect.mapPoint but still fails to achieve goal, any help for this?
编辑:
最终的XML的样子,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res/com.android.game.robbrygame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vScrollview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scrollbars="none" >
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hScrollview"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<View
android:id="@+id/View01"
android:layout_width="280dp"
android:layout_height="150dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:layout_marginTop="83dp"
android:background="#212121"
android:rotation="-5"
android:visibility="visible" />
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
</RelativeLayout>
和我有像许多观点的 View01 等.... !!!
and i have so many view like View01 and so on.... !!!
推荐答案
您可以使用getLocalVisibleRect()
you can use getLocalVisibleRect()
View view01 = findViewById(R.id.View01);
view01.post(new Runnable() {
@Override
public void run() {
view01.getLocalVisibleRect(rectf);
Log.d("WIDTH :", String.valueOf(rectf.width()));
Log.d("HEIGHT :", String.valueOf(rectf.height()));
Log.d("left :", String.valueOf(rectf.left));
Log.d("right :", String.valueOf(rectf.right));
Log.d("top :", String.valueOf(rectf.top));
Log.d("bottom :", String.valueOf(rectf.bottom));
}
});
您需要使用。员额()是河畔的布局设置
you need to use .post() to be sur the layout is set
这篇关于如何旋转视图也通过协调的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文