2016-10-20 3 views
0

私は言語が英語のときにうまく動作するこのナビゲーション引き出しアダプターを持っていますが、言語がアラビア語の場合、いくつかのタイトルセクションには余白があります。ここ は私のXMLである:ここアラビア語の引き出しアダプターのパッド

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/lay" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/blue" 
    android:orientation="horizontal"> 

<ImageView 
    android:id="@+id/top" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:src="@drawable/whitelogo" 
    android:visibility="gone" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:paddingTop="2dp" 
    android:paddingBottom="2dp" 
    android:layout_marginStart="10dp" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="5dp" 
     android:text="test" 
     android:textSize="12sp" 
     android:background="@color/blue" 
     android:textColor="@color/white" /> 
</LinearLayout> 


</RelativeLayout> 

は私のアダプタです。ここ

public class DrawerSectionedAdapter extends BaseAdapter { 


// declaring our ArrayList of items 
private ArrayList<DrawerObject> objects; 
Activity context; 

/* here we must override the constructor for ArrayAdapter 
* the only variable we care about now is ArrayList<Item> objects, 
* because it is the list of objects we want to display. 
*/ 
public DrawerSectionedAdapter(Activity context, int textViewResourceId, ArrayList<DrawerObject> objects) { 

    this.objects = objects; 
    this.context = context; 
} 

@Override 
public int getCount() { 
    return objects.size(); 
} 

@Override 
public Object getItem(int i) { 
    return objects.get(i); 
} 

@Override 
public long getItemId(int i) { 
    return 0; 
} 

/* 
* we are overriding the getView method here - this is what defines how each 
* list item will look. 
*/ 
public View getView(int position, View convertView, ViewGroup parent) { 

    // assign the view we are converting to a local variable 
    View v = convertView; 
    int type = getItemViewType(position); 
    if (v == null) { 
     // Inflate the layout according to the view type 
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     if (type == 0) { 
      // Inflate the layout with image 
      v = inflater.inflate(R.layout.list_item, parent, false); 

     } else 
      v = inflater.inflate(R.layout.value_item, parent, false); 
    } 

    DrawerObject i = objects.get(position); 
    if (i != null) { 

     // This is how you obtain a reference to the TextViews. 
     // These TextViews are created in the XML files we defined. 
     Typeface typeface = null; 
     if (MyApplication.lang.equals("en")) 
      typeface = MyApplication.opensansregular; 
     else 
      typeface = MyApplication.droidregular; 
     if (position == 1) { 
      TextView tt = (TextView) v.findViewById(R.id.name); 
      if (MyApplication.lang.equals("ar")) 
       tt.setGravity(Gravity.RIGHT); 
      else 
       tt.setGravity(Gravity.LEFT); 

     } 
     if (position == 0) { 
      ImageView top = (ImageView) v.findViewById(R.id.top); 
      top.setVisibility(View.VISIBLE); 
      TextView tt = (TextView) v.findViewById(R.id.name); 

      tt.setVisibility(View.GONE); 

      RelativeLayout lay = (RelativeLayout) v.findViewById(R.id.lay); 
      lay.setBackgroundColor(context.getResources().getColor(R.color.white)); 
      tt.setTypeface(typeface); 


     } else { 
      if (type == 0) { 
       ImageView top = (ImageView) v.findViewById(R.id.top); 
       top.setVisibility(View.GONE); 
      } 
      TextView tt = (TextView) v.findViewById(R.id.name); 
      // ViewResizing.textResize(context,tt,15); 
      tt.setText(i.getName()); 
      tt.setVisibility(View.VISIBLE); 
      tt.setTypeface(typeface); 
      RelativeLayout la = (RelativeLayout) v.findViewById(lay); 
      if (MyApplication.lang.equals("en")) 
       la.setLayoutDirection(View.LAYOUT_DIRECTION_LTR); 
      else 
       la.setLayoutDirection(View.LAYOUT_DIRECTION_RTL); 

      if (type != 0) { 
       LinearLayout lin = (LinearLayout) v.findViewById(R.id.linear); 

       if (i.isLastOne()) 
        lin.setBackgroundColor(context.getResources().getColor(R.color.white)); 
       else 
        lin.setBackgroundResource(R.drawable.undertextline); 
      } 

     } 
     // check to see if each individual textview is null. 
     // if not, assign some text! 

    } 

    // the view must be returned to our activity 
    return v; 

} 

@Override 
public int getViewTypeCount() { 
    return 2; 
} 

@Override 
public int getItemViewType(int position) { 
    return (objects.get(position).isTitle()) ? 0 : 1; 
} 

} 

はスクリーンショット(ادراجات参照...) see ادراجات

ある

答えて

0

が解決助けてくださいIT

public class DrawerSectionedAdapter extends BaseAdapter { 


// declaring our ArrayList of items 
private ArrayList<DrawerObject> objects; 
Activity context; 

/* here we must override the constructor for ArrayAdapter 
* the only variable we care about now is ArrayList<Item> objects, 
* because it is the list of objects we want to display. 
*/ 
public DrawerSectionedAdapter(Activity context, int textViewResourceId, ArrayList<DrawerObject> objects) { 

    this.objects = objects; 
    this.context = context; 
} 

@Override 
public int getCount() { 
    return objects.size(); 
} 

@Override 
public Object getItem(int i) { 
    return objects.get(i); 
} 

@Override 
public long getItemId(int i) { 
    return 0; 
} 

/* 
* we are overriding the getView method here - this is what defines how each 
* list item will look. 
*/ 
public View getView(int position, View convertView, ViewGroup parent) { 

    // assign the view we are converting to a local variable 
    View v = convertView; 
    int type = getItemViewType(position); 
    if (v == null) { 
     // Inflate the layout according to the view type 
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     if (type == 0) { 
      // Inflate the layout with image 
      v = inflater.inflate(R.layout.list_item, parent, false); 

     } else 
      v = inflater.inflate(R.layout.value_item, parent, false); 
    } 

    DrawerObject i = objects.get(position); 
    if (i != null) { 

     // This is how you obtain a reference to the TextViews. 
     // These TextViews are created in the XML files we defined. 
     Typeface typeface = null; 
     if (MyApplication.lang.equals("en")) 
      typeface = MyApplication.opensansregular; 
     else 
      typeface = MyApplication.droidregular; 
     if (position == 1) { 
      TextView tt = (TextView) v.findViewById(R.id.name); 
      if (MyApplication.lang.equals("ar")) 
       tt.setGravity(Gravity.RIGHT); 
      else 
       tt.setGravity(Gravity.LEFT); 

     } 
     if (position == 0) { 
      ImageView top = (ImageView) v.findViewById(R.id.top); 
      top.setVisibility(View.VISIBLE); 
      TextView tt = (TextView) v.findViewById(R.id.name); 

      tt.setVisibility(View.GONE); 

      RelativeLayout lay = (RelativeLayout) v.findViewById(R.id.lay); 
      lay.setBackgroundColor(ContextCompat.getColor(context,R.color.white)); 
      tt.setTypeface(typeface); 


     } else { 

      if (type == 0) { 
       ImageView top = (ImageView) v.findViewById(R.id.top); 
       top.setVisibility(View.GONE); 
       RelativeLayout lay = (RelativeLayout) v.findViewById(R.id.lay); 
       lay.setBackgroundColor(ContextCompat.getColor(context,R.color.blue)); 
      } 
      TextView tt = (TextView) v.findViewById(R.id.name); 
      // ViewResizing.textResize(context,tt,15); 
      tt.setText(i.getName()); 
      tt.setVisibility(View.VISIBLE); 
      tt.setTypeface(typeface); 
      RelativeLayout la = (RelativeLayout) v.findViewById(R.id.lay); 
      //la.setBackgroundColor(ContextCompat.getColor(context,R.color.blue)); 
      if (MyApplication.lang.equals("en")) 
       la.setLayoutDirection(View.LAYOUT_DIRECTION_LTR); 
      else 
       la.setLayoutDirection(View.LAYOUT_DIRECTION_RTL); 

      if (type != 0) { 
       LinearLayout lin = (LinearLayout) v.findViewById(R.id.linear); 

       if (i.isLastOne()) 
        lin.setBackgroundColor(ContextCompat.getColor(context,R.color.white)); 
       else 
        lin.setBackgroundResource(R.drawable.undertextline); 
      } 

     } 
     // check to see if each individual textview is null. 
     // if not, assign some text! 

    } 

    // the view must be returned to our activity 
    return v; 

} 

@Override 
public int getViewTypeCount() { 
    return 2; 
} 

@Override 
public int getItemViewType(int position) { 
    return (objects.get(position).isTitle()) ? 0 : 1; 
} 

} 
0



android:paddingStart代わりのandroid:paddingLeft
android:paddingEndの代わりandroid:paddingRight
を使用してみてください。

この問題は、言語がフォームを右から左(RTL)で開始している場合に発生します。だから、Left & Rightの代わりにStart & Endを使用してみてください。

問題が解決しない場合は、教えてください。

関連する問題