我使用monodevelop ti android开发。我想在我的列表末尾添加一个从互联网加载的加载项。 我使用这个xml文件来提出这个建议:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="125dp">
<RelativeLayout
android:id="@+id/LoadingRealtive"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="@drawable/List_Menu_Bg"
>
<ProgressBar
android:id="@+id/loadingListItems"
style="@style/GenericProgressIndicator"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/loadingListItems"
android:id="@+id/textView1"
android:layout_centerHorizontal="true"
android:textColor="#6b6b6b" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/MainRelative"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="@drawable/List_Menu_Bg">...MyListItems </RelativeLayout></LinearLayout>
并在我的列表视图中使用了此代码:
public override View GetView (int position, View convertView, ViewGroup parent)
{
View vi = convertView;
try {
if (convertView == null)
vi = activity.LayoutInflater.Inflate (Resource.Layout.list_row, parent, false);
RelativeLayout LoadingRelative=(RelativeLayout ) vi.FindViewById (Resource .Id.LoadingRealtive);
RelativeLayout ContentRelative=(RelativeLayout ) vi.FindViewById (Resource .Id.MainRelative );
if(Data [position ] == null)
{
ContentRelative .Visibility =ViewStates.Gone ;
LoadingRelative .Visibility = ViewStates.Visible ;
}else{
ContentRelative .Visibility =ViewStates.Visible ;
LoadingRelative .Visibility = ViewStates.Gone ;<...MyListCodes...>
}
} catch (Exception ex) {
Common.HandleException (ex);
}
return vi;
}
它运行正常。问题是加载布局加载wrap_content而它必须加载fill_parent。 我不明白为什么会这样? 有谁能够帮我?
答案 0 :(得分:0)
当使用linearlayout作为包装视图时,你应该将android:weight赋予其具有fill_parent属性的子视图。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="125dp">
<RelativeLayout
android:id="@+id/LoadingRealtive"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="@drawable/List_Menu_Bg"
android:weight="1"
>
<ProgressBar
android:id="@+id/loadingListItems"
style="@style/GenericProgressIndicator"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/loadingListItems"
android:id="@+id/textView1"
android:layout_centerHorizontal="true"
android:textColor="#6b6b6b" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/MainRelative"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="@drawable/List_Menu_Bg"
android:weight="1" >
</RelativeLayout>