View.getRoot()
返回View
,所以我们可以通过使用轻松找出哪个是根视图getResourceName(View.getId())
.
View.getParent()
...,虽然我希望它也返回View
父亲,但实际上只返回一个实例ViewParent
,似乎只有非常少的有用的方法/字段.太糟糕了.
那么,有没有办法知道父母的身份证?我相信一个View
人的父母也是View
,因此它应该有mID字段.
我真的很想知道谷歌为什么不让View.getParent()
回报View
.这是有意义的,只有当其他东西View
可能是父母时,据我所知,它仅限于View
它的子类.
(免责声明:我使用的是Visual Studio 2005的日文版,虽然我将Visual Studio的菜单名称翻译成英文,但它可能与原版的实际版本有所不同)
无论如何,我正在尝试在服务器上发布ClickOnce应用程序,但生成的清单文件(.application)在deploymentProvider代码库属性中有一个我根本无法更改的值.
<deploymentProvider codebase="http://foo.jp/foo/ClickOnce/fooApp.application" />
Run Code Online (Sandbox Code Playgroud)
我期望通过在我们可以指定位置路径的框中放置一个路径来更改该值(我的意思是,解决方案探索 - >属性 - >发布浴缸 - >发布位置),但我是否忽略了其他内容?
当然,我可以在我的NotePad上手动更改它,但我认为这不是正常行为!
我知道多种方法来获取View的位置值.
getLocationOnScreen()
getLocationInWindow()
getLeft()
Run Code Online (Sandbox Code Playgroud)
但是,它们都没有实际返回由startAnimation()方法移动的View I的当前位置,而只返回原始位置.
所以,现在让我们在每个Click上创建一个向右移动10个像素的视图(我省略了布局,因为您可以在主XML中放置任何视图并将其赋予onClickListener).
public class AndroidTestActivity extends Activity implements OnClickListener {
LinearLayout testView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
testView = (LinearLayout) this.findViewById(R.id.test);
testView.setOnClickListener(this);
}
public void onClick(View v) {
int[] pLoS = new int[2];
testView.getLocationOnScreen(pLoS);
TranslateAnimation move = new TranslateAnimation(pLoS[0], pLoS[0] + 10, 0f, 0f);
move.setFillAfter(true);
move.setFillEnabled(true);
testView.startAnimation(move);
}
}
Run Code Online (Sandbox Code Playgroud)
如你所见,这不能按我的意思工作,因为getLocationOnScreen()总是返回相同的值(在我的情况下为0),并且不反映我在TranslateAnimation中使用的值...
任何的想法?
我写了一个类,试图读取服务器发送的字节数据,当我的应用程序结束时,我也希望循环结束,但是NetworkStream.Read()
如果没有数据可用,它似乎等待.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Net;
using System.Threading.Tasks;
namespace Stream
{
class Program
{
private static TcpClient client = new TcpClient("127.0.0.1", 80);
private static NetworkStream stream = client.GetStream();
static void Main(string[] args)
{
var p = new Program();
p.Run();
}
void Run()
{
ThreadPool.QueueUserWorkItem(x =>
{
while (true)
{
stream.Read(new byte[64], 0, 64);
}
});
client.Close();
// insert Console.ReadLine(); if you want to see an exception occur.
}
} …
Run Code Online (Sandbox Code Playgroud)