【问题标题】:How do I allign the Text in one column of a Gridview in android如何在android中的Gridview的一列中对齐文本
【发布时间】:2014-09-13 12:26:20
【问题描述】:

我的程序在应用程序上显示一个网格视图,左列中显示数字,右列中显示名称。我希望左列中的数字与右侧对齐,而不是它们当前与左侧对齐的方式。我在网上尝试了几种解决方案,但似乎都没有奏效。 前任。 当前:

500000   |nameofstuff
3203     |stuffstuff
33       |lalalalala

想要的:

 500000|nameofstuff                        
   3203|stuffstuff    
     33|lalalalala

当前的 GridView 设置。我可能做错了什么。

    GridView gridView = (GridView)findViewById(R.id.gridView1);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, arr);

    gridView.setAdapter(adapter);

    gridView.setOnItemClickListener(new OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int pos, long id) 
        {
            Toast.makeText(getApplicationContext(), ((TextView) v).getText(), Toast.LENGTH_SHORT).show();
        }
    });

xml,目前这里真的什么都没有,因为我尝试过的所有尝试都没有奏效

  <GridView
    android:id="@+id/gridView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top|right"
    android:numColumns="2" >
  </GridView>

【问题讨论】:

    标签: android gridview text alignment


    【解决方案1】:

    您可能需要创建一个自定义适配器并覆盖 getView() 方法以根据位置设置 textview 的重力。

    您可以参考以下链接获取自定义适配器-http://www.stealthcopter.com/blog/2010/09/android-creating-a-custom-adapter-for-gridview-buttonadapter/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-03
      • 2020-12-01
      • 2011-12-26
      • 1970-01-01
      • 2018-07-31
      • 2014-05-26
      • 2020-09-06
      • 2012-06-21
      相关资源
      最近更新 更多