在这两种方法的上下文中,屏幕和视图有什么区别?
我有一个按钮,我想得到它的中心的x坐标.
我想这就足够了:
public int getButtonXPosition() {
return (button.getLeft()+button.getRight())/2;
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用它会有什么不同
getLocationOnScreen()
还是getLocationInWindow()
?
(当然,添加按钮宽度的一半)
我想使用ScaleAnimation(以编程方式不在xml中)更改高度以查看父高度的0到60%.视图宽度恒定,为50px.视图为空,仅设置背景颜色.
有人可以给我代码scaleAnim
从代码中使用ScaleAnimation.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layContainer
>
<View
android:layout_width="50px"
android:layout_height="fill_parent"
android:id="@+id/viewContainer"
android:background:"#00f00"
/>
</LinearLayout>
ScaleAnimation scaleAnim = new ScaleAnimation(...);
Run Code Online (Sandbox Code Playgroud)
在动画之前和之后查看.谢谢
我有一些观点,按下按钮后可以看到.如果我点击这些视图之外,我希望它们消失.
如何在Android上完成?
此外,我意识到"后退按钮"也可以帮助Android用户 - 我可能会将其作为关闭视图的第二种方式 - 但有些平板电脑甚至不再使用"物理"后退按钮,它一直非常不再强调.
我通过处理一个View Item的触摸事件从我的屏幕获取真实(x,y)时遇到了一些麻烦.
我有这个:
当我触摸View项目时,它会给我坐标位于左上角的原点,如果我将手指滑出视图,它会给我负坐标(向上或向左滑动时).
我想在屏幕上获取View位置,将其添加到我得到的(x,y)坐标,因此最终结果是(0,0)位于整个屏幕的左上角.
我还需要总的屏幕尺寸,以便我知道手指何时位于右下角.
我怎样才能做到这一点?
谢谢.
我想在显示屏上找到视图的位置.
要做到这一点,我用的方法,如view.getLeft()
,view.getBottom()
,view.getRight()
,view.getTop()
.但不幸的是,所有这些方法都被退回了0
.
有没有其他方法可以找到视图的位置(即屏幕上的坐标)?
我的布局main.xml
:
<TextView android:id="@+id/tv1"
android:layout_width="200px"
android:layout_height="30px"
android:text="welcome to" />
<TextView android:id="@+id/tv2"
android:layout_width="200px"
android:layout_height="30px"
android:text=" Make Eit solution " />
Run Code Online (Sandbox Code Playgroud)
我的班级有这个onCreate()
:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv1 = (TextView) findViewById(R.id.tv1);
tv2 = (TextView) findViewById(R.id.tv2);
System.out.println("tv4 width:"+tv2.getWidth());
System.out.println("tv4 height:"+tv2.getHeight());
System.out.println("Right:"+tv2.getRight());
System.out.println("Left:"+tv2.getLeft());
System.out.println("Top:"+tv2.getTop());
System.out.println("Bottom:"+tv2.getBottom());
Run Code Online (Sandbox Code Playgroud) 给定a TextView
,是否可以在运行时知道绘制位置的X和Y坐标?是否也可以知道像素的大小(宽度/长度)?
我有类似这样的问题:用动画更新布局
基本上:我有一个带有edittext,按钮和列表的垂直LinearLayout视图.我想在按下按钮后隐藏exittext,为列表腾出更多空间(按钮会上升).在第二次按下edittext应该再次可见.Edittext和按钮具有"wrap_content"高度.
我想用动画隐藏和显示edittext.
我成功地通过重载动画的applyTransformation来动画隐藏:
final float edittextheight= edittext.getHeight();
[....]
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t)
{
super.applyTransformation(interpolatedTime, t);
android.view.ViewGroup.LayoutParams lp = edittext.getLayoutParams();
lp.height = (int)(edittextheight*(1.0-interpolatedTime));
edittext.setLayoutParams(lp);
}
Run Code Online (Sandbox Code Playgroud)
问题:
我不知道如何计算动画显示的高度 - edittext.getHeight(); 隐藏窗口小部件时返回0,并且在布局定义中我使用"wrap_content".
救命?
我需要ScrollView
在活动启动期间检索布局xml文件中定义的高度.哪个是实现此目的的最佳实践.我试过把代码放在里面onCreate()
,onStart()
然后onResume()
.All在启动时将高度设为0.是否有像活动一样onFinishInflate()
的方法?
这是我的代码:
myScroll=(ScrollView) findViewById(R.id.ScrollView01);
int height=myScroll.getHeight();
Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的示例来了解如何获取任何给定的坐标view
。以下是我的尝试,它们总是显示0.0
。知道为什么会发生这种情况吗?
代码:
private int [] tv1Location = new int[2];
private int [] tv2Location = new int[2];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Rect tv1Rect = new Rect();
Rect tv2Rect = new Rect();
TableLayout tl = (TableLayout) findViewById(R.id.tableLayout);
TextView tv1 = (TextView) findViewById(R.id.tv1);
TextView tv2 = (TextView) findViewById(R.id.tv2);
tv1.getLocalVisibleRect(tv1Rect);
tv1.getLocationOnScreen(tv1Location);
tv2.getLocalVisibleRect(tv1Rect);
tv2.getLocationOnScreen(tv2Location);
tv1.setText("xCords: "+tv1.getX()+", yCords: "+tv1.getY());
tv2.setText("xCords: "+tv2.getX()+", yCords: "+tv2.getY());
//tv2.setText("xCords: "+tv2Location[0]+", yCords: "+tv2Location[1]);
//tv1.setText("xCords: "+tv1Location[0]+", yCords: "+tv1Location[1]);
//tv2.setText("xCords: "+tv2Location[0]+", yCords: "+tv2Location[1]);
Run Code Online (Sandbox Code Playgroud)
更新
@Override
public …
Run Code Online (Sandbox Code Playgroud)