开发者

Source not found Exception while setting layoutparameters

开发者 https://www.devze.com 2023-03-11 08:07 出处:网络
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

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 开发者_如何学Cwhen 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);


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号