Tôi đã thực hiện một tuỳ chỉnh Viewgroup
mà tôi cần sử dụng trong đơn đăng ký của mình, nhưng tôi cần phải đặt nó trong một số ScrollView
. Khi bố trí được thực hiện chỉ với tùy chỉnh của tôi ViewGroup
tất cả mọi thứ hoạt động tốt, nhưng khi tôi đặt nó trong một ScrollView
tôi không thể nhìn thấy bất cứ điều gì. bố trí của tôi:ScrollView tạo bố cục tùy chỉnh ẩn
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.example.test.CustomLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.example.test.CustomLayout>
</ScrollView>
ViewGroup của tôi:
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
/* do something and call for each child
View v = getChildAt(i);
v.measure(wspec, hspec);
*/
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
//do something and call layout on every child
}
UPDATE: lớp CustomLayout My
public class CustomLayout extends ViewGroup{
/*My params*/
public CustomLayout(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public CustomLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
//do something and call layout on every child
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
/* do something and call for each child
View v = getChildAt(i);
v.measure(wspec, hspec);
*/
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}
}
UPDATE 2: Xin lỗi nhưng tôi thực hiện một số cố gắng khác và có vẻ như nếu Tôi có viewgroup trong một scrollview trên phương pháp onMeasure tôi đã heightMeasureSpec = 0, sau đó nếu tôi đặt viewgroup trong bất kỳ bố trí khác, tôi có một số nguyên. Có lẽ điều này sẽ giúp?
Cố gắng đó, kết quả không có. – DLock