我正在尝试创建一个可以ImageView在您的设备上移动的应用程序,例如拖动,当我放置75%ImageView的屏幕外显示Toast例如.我一直在阅读有关MotionEvent和onTouchListener我已经遵循了这一问题,但它并没有说服我.
我目前的代码是:
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
int windowwidth;
int windowheight;
private ImageView mImageView;
private ViewGroup mRrootLayout;
private int _xDelta;
private int _yDelta;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
windowwidth = displaymetrics.widthPixels;
windowheight = displaymetrics.heightPixels;
mRrootLayout = (ViewGroup) findViewById(R.id.root);
mImageView = (ImageView) mRrootLayout.findViewById(R.id.im_move_zoom_rotate);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(150, 150);
mImageView.setLayoutParams(layoutParams);
mImageView.setOnTouchListener(this);
}
public boolean onTouch(View view, …Run Code Online (Sandbox Code Playgroud) 我正在创建一些自定义的remoteViews,为了将自定义视图和布局绘制到与通知面板一样宽的位图,我需要它的确切宽度.
由于每个供应商都会更改通知面板的宽度,并且在大多数情况下会根据方向进行更改,因此很难找到常规模式.
有没有办法得到它的宽度?
粉红色部分是纯粹的remoteViews,底部是imageview,我将自定义视图绘制到它,因为我没有父宽度,所有子视图都会崩溃.
android android-custom-view android-notifications remoteview
我需要优化我的Android应用,以便在具有缺陷的手机上看起来很好,比如Essential Phone.
此手机的状态栏高度与标准25dp值不同,因此您无法对该值进行硬编码.
昨天发布的Android P开发者预览版包括对缺口和一些API的支持,以查询其位置和边界,但对于我的应用程序,我只需要能够从XML获取状态栏高度,而不是使用固定值.
不幸的是,我找不到任何方法从XML中获取该值.
有什么办法吗?
谢谢.
我想获取Android设备的屏幕尺寸。我正在使用这3个代码来执行此操作,但这给了我活动的大小;没有状态栏高度的大小。在高度为800px的平板电脑上,此代码为764px。36px转到底部的状态栏。
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
final int width = size.x;
final int height = size.y;
Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int height2= rectgle.bottom;
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int actualHeight = metrics.heightPixels;
Run Code Online (Sandbox Code Playgroud)
但是我需要一个代码,该代码可以给我 实际的屏幕尺寸。 不是活动的。有人可以帮我吗?谢谢。
我正在游戏上使用 Appium 1.3.2 运行一些测试。我试图点击一个我知道坐标的元素的右下角,在许多设备上我遇到了 Appium 报告坐标无效的问题,因为它们位于屏幕之外。
我检查了 Appium 报告的大小:
driver.manage().window().getSize()
Run Code Online (Sandbox Code Playgroud)
并注意到在实际分辨率为 960x540 的设备上报告的窗口大小为 886x540。
另外,只要尝试单击右下角,就会在 Appium 日志中生成以下内容:
[36minfo[39m: [debug] Pushing command to appium work queue ["element:touchDown",{"x":889,"y":473}]
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":889,"y":473}}
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Got command action: touchDown
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][886,540]
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Coordinate [x=889.0, y=473.0] is outside of element rect: [0,0][886,540]","status":29}
[36minfo[39m: [debug] Responding to client with …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个全屏活动。我希望我的页面标题位于状态栏下方。如何测量全屏活动中状态栏的高度?
我对此进行了研究并尝试了它们。其中之一是this,它使用了 xml 中的一个属性,但在我的情况下不起作用。另一种是第二种解决方案
val rectangle = Rect()
window.decorView.getWindowVisibleDisplayFrame(rectangle)
val statusBarHeight = rectangle.top
Run Code Online (Sandbox Code Playgroud)
statusBarHeight是 0,因为它可能是全屏活动。有什么帮助可以将我的一些元素(例如标题)放置在状态栏工作人员下方吗?