设置布局参数时未找到源异常
嗨,我是安卓世界的新手。我正在开发一个支持阿拉伯语和英语的应用程序。因此,我在 xml 中针对英语进行了设计,并通过代码,当用户想要使用阿拉伯语时,我更改了小部件的重力以匹配阿拉伯语的右侧向左看。
现在我有两个问题:- 1-我必须实施虚拟阿拉伯语键盘吗?
2-我有一个列表,显示从右到左开始的论坛线程。为了制作此列表,我有 2 个 xml,一个用于列表,另一个用于列表行。当用户的语言是阿拉伯语时,我为 xml 中的每个小部件设置 ALIGN_PARENT_RIGHT。它适用于列表 xml,但是当我尝试为列表的行创建它时,它会抛出源未找到异常。
可以帮助我吗?
//threads row
//lastPost
tvThread=(TextView)findViewById(R.id.txtLastPost);
//here it throws the exception
params = (RelativeLayout.LayoutParams)tvThread.getLayoutParams();
params.setMargins(20, 0, 0, 0);
Hi I'm new to android world. I'm working on an application that supports arabic and english languages.So I made my design for english language in the xml and through the code when the user wants to work with arabic language I change the gravity of my widgets to match the arabic right-to-left look.
Now I have 2 questions:-
1-Will I have to implement virtual arabic keyboard?
2-I have a list that shows a forum's threads to start from right-to-left.To make this list I have 2 xmls one for the list and the other for the list's row. When the user's language is arabic I make ALIGN_PARENT_RIGHT for each widget in my xmls. It works for the list xml but when I try to make this for the list's row It throws source not found exception.
Could help me?
//threads row
//lastPost
tvThread=(TextView)findViewById(R.id.txtLastPost);
//here it throws the exception
params = (RelativeLayout.LayoutParams)tvThread.getLayoutParams();
params.setMargins(20, 0, 0, 0);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的 TextView 包含在某些其他布局元素中,而不是您的relativelayout的直接子元素(可能),您不应该将其参数转换为relativelayout。将其转换为容器布局,或者仅使用通用 LayoutParams。应该可以正常工作
If your TextView is contained within some other Layout Element, and not a direct child of your RelativeLayout (likely) you shouldn't cast it's params as relativelayout. Cast it as whatever it's container layout is, or just use generic LayoutParams. Should work fine as