2014-09-22 89 views
0

我有什麼是自定義網格視圖,每行包含五列,每個單元格內有一個文本視圖,我希望這個文本視圖在右邊電池的一面,但它一直顯示在左側。由於這一形象: enter image description here我無法使網格視圖內的單元格的textview權利

這裏是我的網格視圖XML文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" 
    tools:ignore="MergeRootFrame" 
    android:layout_gravity="right" > 

    <GridView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/myGridView" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:gravity="right" 
     android:layout_marginTop="60dp"   
     android:numColumns="5" 
     android:textDirection="rtl"/> 


</RelativeLayout> 

這裏是TextView的風格XML文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/grid_item" 
     android:layout_width="318dp" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:text="Medium Text" 
     android:textAlignment="gravity" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#000000" 
     android:textSize="20sp" /> 

</LinearLayout> 

這裏是我的主要活動:

public class MyOrderNew extends Activity { 

    private TextView text; 
    private GridView gridView; 
    private final String[] items = new String[]{"ملاحظات","مربع المساحة","الإرتفاع","العرض","الصنف","7","8","9","10","11"}; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.cart); 



     gridView = (GridView) this.findViewById(R.id.myGridView); 
     gridView.setBackgroundColor(Color.BLUE); 
     gridView.setVerticalSpacing(1); 
     gridView.setHorizontalSpacing(1); 
     CustomGridAdapter gridAdapter = new CustomGridAdapter(MyOrderNew.this, items); 
     gridView.setAdapter(gridAdapter); 

誰能幫我解決這個問題?

回答

1

給寬度填充父到文本視圖,並重力右。或佈局權重。

+0

它的工作原理:D我會檢查你的答案 – sereen 2014-09-22 07:48:47

0

不要固定TextView的寬度使其FILL_PARENT 機器人:layout_width =「FILL_PARENT」

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/grid_item" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:text="Medium Text" 
     android:textAlignment="gravity" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#000000" 
     android:textSize="20sp" /> 

</LinearLayout> 
相關問題