【问题标题】:Issue with ListView alignmentListView 对齐问题
【发布时间】:2012-02-14 11:45:39
【问题描述】:

我在 xml 中有一个列表视图,layout_widthlayout_height 都为 fill_parent

我使用 android 提供的默认布局为android.R.layout.simple_list_item_1。但由于它是 android 提供的默认布局,我无法在中心对齐。默认对齐是左侧。无论如何要做到这一点。我知道我可以制作自己的 textview 并作为 R.layout.my_textView 提供。但无论如何要使用该默认布局使 listview 项目居中。

【问题讨论】:

  • android:gravity="center" 可能会帮助您对齐中心
  • android:gravity="center_horizo​​ntal" 也许也是?这里stackoverflow.com/questions/1499555/…
  • 请大家至少阅读我的问题 2 遍然后给出答案。
  • 我试图找出每行加载到列表视图中间的相同之处。
  • @PradeepBhatu 复制该默认 xml 文件并使用重心制作您自己的文件。

标签: android listview


【解决方案1】:

你能把你的布局吗?错误可能是您缺少“android:gravity="center""

【讨论】:

【解决方案2】:

您可以通过在呈现视图时设置重力、边距或其他任何内容,在适配器的 getView 方法中覆盖系统 TextView 的部分布局。

【讨论】:

    【解决方案3】:

    对于居中的 textview 对齐,您可以创建自定义行 xml 要创建自定义行 xml,请遵循该文档 http://devblogs.net/2011/01/04/custom-listview-with-image-using-simpleadapter/

    【讨论】:

    • schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" >
    • 请再次阅读我的问题
    【解决方案4】:

    使用RelativeLayout并设置android:layout_centerHorizontal="true"

    更新: 这是一行的布局

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" >
    
        <TextView
            android:id="@+id/label"
            android:text="@+id/label"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />
    
    </RelativeLayout>
    

    【讨论】:

    • 对不起,我的意思是 android:layout_centerHorizo​​ntal="true"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    • 2018-10-28
    • 2011-11-12
    • 2011-05-06
    • 2011-04-22
    相关资源
    最近更新 更多