设置布局参数时未找到源异常

发布于 2024-11-13 11:14:31 字数 553 浏览 3 评论 0原文

嗨,我是安卓世界的新手。我正在开发一个支持阿拉伯语和英语的应用程序。因此,我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的年少不轻狂 2024-11-20 11:14:31

如果您的 TextView 包含在某些其他布局元素中,而不是您的relativelayout的直接子元素(可能),您不应该将其参数转换为relativelayout。将其转换为容器布局,或者仅使用通用 LayoutParams。应该可以正常工作

// params defined somewhere previously as something like LayoutParams params;
params = tvThread.getLayoutParams();
params.setMargins(20, 0, 0, 0);

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

// params defined somewhere previously as something like LayoutParams params;
params = tvThread.getLayoutParams();
params.setMargins(20, 0, 0, 0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文