Android layout Android ListActivity没有';不要把东西放在中心
我有一个ListActivity,它显示一个图像和一些文本。 imageView具有固定的大小,我希望将列表水平居中。 在无休止的尝试之后,我将任何重力设置为水平中心,但没有任何效果 列表显示在整个屏幕上,我可以通过右侧的滚动条看到。但我的框架仍然在左边。 在adapter类(entends ArrayAdapter)中,我甚至尝试在运行时设置重力,但当我尝试操纵基本线性布局时,我得到了错误:Android layout Android ListActivity没有';不要把东西放在中心,android-layout,listview,adapter,listadapter,layout-gravity,Android Layout,Listview,Adapter,Listadapter,Layout Gravity,我有一个ListActivity,它显示一个图像和一些文本。 imageView具有固定的大小,我希望将列表水平居中。 在无休止的尝试之后,我将任何重力设置为水平中心,但没有任何效果 列表显示在整个屏幕上,我可以通过右侧的滚动条看到。但我的框架仍然在左边。 在adapter类(entends ArrayAdapter)中,我甚至尝试在运行时设置重力,但当我尝试操纵基本线性布局时,我得到了错误: "java.lang.ClassCastException: android.widget.Linea
"java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams"
LinearLayout layout = (LinearLayout) rowView.findViewById(R.id.bootsFrameLayout);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER_HORIZONTAL;
layout.setLayoutParams(params);
我试图在方法getView()中更改重力,该方法引发错误:
"java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams"
LinearLayout layout = (LinearLayout) rowView.findViewById(R.id.bootsFrameLayout);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER_HORIZONTAL;
layout.setLayoutParams(params);
列表行在布局文件中设计:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bootsFrameLayout"
android:layout_width="300dp"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/card_blank2"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/bootsName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="TextView"
android:textAppearance="@style/BootNameStyle" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="30dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginStart="30dp" >
<ImageView
android:id="@+id/bootImage"
android:layout_width="240dp"
android:layout_height="180dp"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/test_boot" />
<TextView
android:id="@+id/textWatchList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/gray_transparent"
android:gravity="end"
android:lines="2"
android:text="@string/watchlist"
android:textAppearance="@style/BootWatchListStyle" />
<ProgressBar
android:id="@+id/bootProgressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="invisible" />
</FrameLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginStart="25dp" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/bootMasse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="70"
android:text="TextView"
android:textAppearance="@style/BootInfoStyle" />
<TextView
android:id="@+id/bootBaujahr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="30"
android:gravity="right"
android:text="TextView"
android:textAppearance="@style/BootInfoStyle" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/bootLand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="70"
android:text="TextView"
android:textAppearance="@style/BootInfoStyle" />
<TextView
android:id="@+id/bootPreis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="30"
android:gravity="right"
android:text="TextView"
android:textAppearance="@style/BootPreisStyle" />
</TableRow>
</TableLayout>
ListView定义如下:
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="12dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginStart="12dp"
android:layout_weight="8" >
</ListView>
活动占据了整个屏幕,正如它应该做的那样。
但是,尽管有足够的位置,框架不会居中
有什么想法吗