• <legend id='hSnpp'><style id='hSnpp'><dir id='hSnpp'><q id='hSnpp'></q></dir></style></legend>

    <i id='hSnpp'><tr id='hSnpp'><dt id='hSnpp'><q id='hSnpp'><span id='hSnpp'><b id='hSnpp'><form id='hSnpp'><ins id='hSnpp'></ins><ul id='hSnpp'></ul><sub id='hSnpp'></sub></form><legend id='hSnpp'></legend><bdo id='hSnpp'><pre id='hSnpp'><center id='hSnpp'></center></pre></bdo></b><th id='hSnpp'></th></span></q></dt></tr></i><div id='hSnpp'><tfoot id='hSnpp'></tfoot><dl id='hSnpp'><fieldset id='hSnpp'></fieldset></dl></div>

    • <bdo id='hSnpp'></bdo><ul id='hSnpp'></ul>

      <tfoot id='hSnpp'></tfoot>
    1. <small id='hSnpp'></small><noframes id='hSnpp'>

      1. 如何在Android中获取文本方向并根据方向动态更改布局?

        How to get text direction in Android and change layout dynamically according to the direction?(如何在Android中获取文本方向并根据方向动态更改布局?)
        <tfoot id='kxlf7'></tfoot>

          <tbody id='kxlf7'></tbody>

      2. <i id='kxlf7'><tr id='kxlf7'><dt id='kxlf7'><q id='kxlf7'><span id='kxlf7'><b id='kxlf7'><form id='kxlf7'><ins id='kxlf7'></ins><ul id='kxlf7'></ul><sub id='kxlf7'></sub></form><legend id='kxlf7'></legend><bdo id='kxlf7'><pre id='kxlf7'><center id='kxlf7'></center></pre></bdo></b><th id='kxlf7'></th></span></q></dt></tr></i><div id='kxlf7'><tfoot id='kxlf7'></tfoot><dl id='kxlf7'><fieldset id='kxlf7'></fieldset></dl></div>
        <legend id='kxlf7'><style id='kxlf7'><dir id='kxlf7'><q id='kxlf7'></q></dir></style></legend>
        • <bdo id='kxlf7'></bdo><ul id='kxlf7'></ul>

        • <small id='kxlf7'></small><noframes id='kxlf7'>

                  本文介绍了如何在Android中获取文本方向并根据方向动态更改布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在研究根据文本方向动态更改 UI 的可行性.尽管 Google 支持 RTL 语言(参考: 类.这个类有 在 if 语句中使用可能会更好.结果和上面一样.

                  Bidi bidi = new Bidi(userList.get(position).getName(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);if(bidi.baseIsLeftToRight())convertView = myInflater.inflate(R.layout.list_add_friends_row, null);别的convertView = myInflater.inflate(R.layout.list_add_friends_row_mirror, null);

                  I'm doing some research about feasibility of changing UI dynamically based on direction of a text. Although Google is supporting RTL languages (ref: Native RTL support in Android 4.2) but it doesn't cover a situation that application has mix of LTR and RTL contents.

                  Google's solution is right if we have multilingual app and it has different sources of static data (such as menu items) in different languages. However, I didn't find any other document regard how to change layout dynamically based on direction of text content.

                  Following image shows current design of my test app. List comes from Facebook (list of my friends) and contains English and Persian names.

                  My solution is having two layouts (one for LTR and one for RTL) in adapter and assigning each one based on direction of name. So, I wrote following lines of code:

                  @Override
                      public View getView(final int position, View convertView, ViewGroup parent) {
                          ViewHolder holder;
                  
                              if(position % 2 == 0)
                                  convertView = myInflater.inflate(R.layout.list_add_friends_row, null);
                              else
                                  convertView = myInflater.inflate(R.layout.list_add_friends_row_mirror, null);
                  
                              holder = new ViewHolder();
                  
                              holder.llSection = (LinearLayout) convertView.findViewById(R.id.section);
                              holder.tvUserName = (TextView) convertView.findViewById(R.id.tvUserName);
                              holder.ivPicture = (ImageView) convertView.findViewById(R.id.ivPicture);
                              holder.btnAdd = (Button) convertView.findViewById(R.id.btnAdd);
                  
                              convertView.setTag(holder);
                  
                  
                  
                          holder.btnAdd.setTag(position);
                          holder.tvUserName.setText(userList.get(position).getName());
                          imageDownloader.displayImage(holder.ivPicture, userList.get(position).getPhotoUrl());
                  
                          ...
                  
                          return convertView;
                      }
                  

                  and result is:

                  I mirrored rows based on if row is even or odd. Now, my question is how to mirror UI based on name. I think I should change clause condition from if(position % 2 == 0) to something like if(isNameLTR(FIRST_CHAR_OF_NAME)). I have no idea how to implement this method.

                  How can I know a character is LTR ot RTL? (I think Android knows first character of word is RTL or LTR that's why when width of text view is match parent it align text to right if character is RLT and to left if character is LTR).

                  Any suggestion or comments would be appreciated. Thanks

                  解决方案

                  Solution, was easier that I was thinking :) Thanks to JAVA

                  There is Bidi class. This class has getBaseLevel() method which returns 0 if your text is left-to-right otherwise 1 (if right-to-left).

                  So, this is my code:

                  @Override
                      public View getView(final int position, View convertView, ViewGroup parent) {
                          ViewHolder holder;
                  
                          Bidi bidi = new Bidi(userList.get(position).getName(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
                          if(bidi.getBaseLevel() == 0)
                              convertView = myInflater.inflate(R.layout.list_add_friends_row, null);
                          else
                              convertView = myInflater.inflate(R.layout.list_add_friends_row_mirror, null);
                  
                  ...
                  

                  and result is:

                  =============

                  Update:

                  There is another method, baseIsLeftToRight() that might be better to be used in if statement. Result was same as above.

                  Bidi bidi = new Bidi(userList.get(position).getName(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);
                  if(bidi.baseIsLeftToRight())
                                  convertView = myInflater.inflate(R.layout.list_add_friends_row, null);
                              else
                                  convertView = myInflater.inflate(R.layout.list_add_friends_row_mirror, null);
                  

                  这篇关于如何在Android中获取文本方向并根据方向动态更改布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员
                  quot;Auto Layout still required after executing -layoutSubviewsquot; with UITableViewCell subclass(“执行 -layoutSubviews 后仍需要自动布局带有 UITableViewCell 子类)

                  <small id='bp5Hy'></small><noframes id='bp5Hy'>

                1. <i id='bp5Hy'><tr id='bp5Hy'><dt id='bp5Hy'><q id='bp5Hy'><span id='bp5Hy'><b id='bp5Hy'><form id='bp5Hy'><ins id='bp5Hy'></ins><ul id='bp5Hy'></ul><sub id='bp5Hy'></sub></form><legend id='bp5Hy'></legend><bdo id='bp5Hy'><pre id='bp5Hy'><center id='bp5Hy'></center></pre></bdo></b><th id='bp5Hy'></th></span></q></dt></tr></i><div id='bp5Hy'><tfoot id='bp5Hy'></tfoot><dl id='bp5Hy'><fieldset id='bp5Hy'></fieldset></dl></div>

                          <tfoot id='bp5Hy'></tfoot>
                        • <legend id='bp5Hy'><style id='bp5Hy'><dir id='bp5Hy'><q id='bp5Hy'></q></dir></style></legend>
                            <bdo id='bp5Hy'></bdo><ul id='bp5Hy'></ul>

                              <tbody id='bp5Hy'></tbody>