我有以下布局,显示联系人详细信息,还有一个可扩展列表。但问题是可扩展列表视图是固定的,但我已经给它填充了fill_parent,所以它必须采用可用的全高度。此外,滚动视图仅应用于列表而不是整个布局。如果有人有任何想法,请帮助我。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:scrollbars="vertical|horizontal" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:id="@+id/vsHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/header" >
<Button
android:id="@+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="@drawable/home"
android:onClick="btnHomeClick" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/contactheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/vsHeader"
android:padding="5dip" >
<TextView
android:id="@+id/txtContactName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Hello Taxi"
android:textColor="@color/autoText"
android:textSize="@dimen/text_size_large"
android:textStyle="bold" />
<ImageView
android:id="@+id/img_address"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_below="@id/txtContactName"
android:layout_marginBottom="5dip"
android:contentDescription="@string/content_description"
android:src="@drawable/address" />
<TextView
android:id="@+id/txt_Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtContactName"
android:layout_marginBottom="15dip"
android:layout_marginLeft="15dip"
android:layout_toRightOf="@+id/img_address"
android:maxLines="5"
android:singleLine="false"
android:textColor="@color/autoText" />
<ImageView
android:id="@+id/img_phone"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_below="@id/txt_Address"
android:layout_marginBottom="5dip"
android:contentDescription="@string/content_description"
android:src="@drawable/contact_no" />
<TextView
android:id="@+id/txtPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txt_Address"
android:layout_marginBottom="15dip"
android:layout_marginLeft="15dip"
android:layout_toRightOf="@id/img_phone"
android:textColor="@color/autoText" />
<ImageView
android:id="@+id/img_mobile"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_below="@id/txtPhone"
android:layout_marginBottom="5dip"
android:contentDescription="@string/content_description"
android:src="@drawable/mobile" />
<TextView
android:id="@+id/txtmobilenumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtPhone"
android:layout_marginBottom="15dip"
android:layout_marginLeft="15dip"
android:layout_toRightOf="@id/img_mobile"
android:textColor="@color/autoText" />
<ImageView
android:id="@+id/img_web"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_below="@id/txtmobilenumber"
android:layout_marginBottom="5dip"
android:contentDescription="@string/content_description"
android:src="@drawable/www" />
<TextView
android:id="@+id/txtweb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtmobilenumber"
android:layout_marginBottom="15dip"
android:layout_marginLeft="15dip"
android:layout_toRightOf="@id/img_web"
android:textColor="@color/autoText" />
<ImageView
android:id="@+id/img_email"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_below="@id/txtweb"
android:layout_marginBottom="15dip"
android:contentDescription="@string/content_description"
android:src="@drawable/mail" />
<TextView
android:id="@+id/txtemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtweb"
android:layout_marginBottom="15dip"
android:layout_marginLeft="15dip"
android:layout_toRightOf="@id/img_email"
android:textColor="@color/autoText" />
<Button
android:id="@+id/btn_rate_it"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_below="@id/img_email"
android:layout_centerHorizontal="true"
android:background="@drawable/greenbutton"
android:text="@string/rate_it"
android:textColor="#ffffff" />
</RelativeLayout>
<ExpandableListView
android:id="@+id/expandable_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/contactheader"
android:layout_marginTop="10dip"
android:groupIndicator="@drawable/group_indicator" />
</RelativeLayout>
</ScrollView>
图片: - 您可以看到只有列表视图滚动,因此滚动UI时会变得有些难看。我不想这样做。我希望整个布局滚动。
答案 0 :(得分:2)
我知道为时已晚,但我为遇到此问题的其他人写过。问题是当你在Scrollview中使用ExpandableListView时,ExpandableListView高度未正确定义。所以我以编程方式计算高度:
//for converting dp to pixel
final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
//when all the headers are Collapse
expListView.getLayoutParams().height=listDataHeader.size()*(int) (43 * scale + 0.5f);
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
expListView.getLayoutParams().height+=listDataChild.get(listDataHeader.get(groupPosition)).size()*(int) (34 * scale + 0.5f);
}
});
// Listview Group collasped listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
expListView.getLayoutParams().height-=listDataChild.get(listDataHeader.get(groupPosition)).size()*(int) (34 * scale + 0.5f);
}
});