내 응용 프로그램에서 사용해야하는 사용자 정의 Viewgroup
을 만들었지 만, ScrollView
에 넣어야합니다. 레이아웃이 내 사용자 정의로만 이루어질 때 ViewGroup
모든 것이 잘 작동하지만, 이것을 ScrollView
에 넣으면 아무 것도 볼 수 없습니다. 내 레이아웃 :ScrollView가 사용자 정의 레이아웃을 보이지 않게합니다.
<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>
내 뷰 그룹 :
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 : 내 CustomLayout 클래스 2
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 : 미안하지만 난 다른 시도를했고이 경우처럼 보인다 나는 viewMember 메서드를 사용하여 viewModel에 viewGroup을 가지고 있는데, heightMeasureSpec = 0이면 다른 뷰에 뷰 그룹을 놓으면, 정수가있어. 어쩌면이게 도움이 될까요? 또한 오른쪽 아래에이 생성자를 사용하는 layout_height
, 아니 그 결과 다음과 같은 코드 아래에 추가합니다. – DLock