大家晚安!
我正在尝试在触摸事件后调整自定义视图(RelativeLayout)的高度,但无法正常工作。
想法是:我获得了一个自定义的RelativeLayout作为页脚视图,并且在另一视图的触摸事件中,我更改了页脚的内容。每个孩子都有不同的身高,因此页脚视图必须根据孩子的身高来适应自己。
基本上,调整大小的操作很好,我在页脚视图中设置了新的高度值,可以看到屏幕随着新区域的刷新,但是在页脚视图返回到旧的高度值之后。
屏幕布局:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:id="@+id/lTudo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGreen">
<RelativeLayout
android:id="@+id/lTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryOn">
<LinearLayout
android:id="@+id/lTopPergunta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="1"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="8dp">
<TextView
android:id="@+id/labelConhecendoVoce"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Conhecendo você"
android:textColor="@color/colorWhite"
android:textSize="17dp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/lQuadradinhos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/quadradinho_white_on" />
<ImageView
android:id="@+id/quadrado2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:background="@drawable/quadradinho_white_off" />
<ImageView
android:id="@+id/quadrado3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:background="@drawable/quadradinho_white_off" />
<ImageView
android:id="@+id/quadrado4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:background="@drawable/quadradinho_white_off" />
<ImageView
android:id="@+id/quadrado5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:background="@drawable/quadradinho_white_off" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/lTopPendencia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="8dp"
android:visibility="gone">
<TextView
android:id="@+id/labelTitlePendencia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Conhecendo você"
android:textColor="@color/colorWhite"
android:textSize="17dp"
android:textStyle="bold" />
</LinearLayout>
<RelativeLayout
android:id="@+id/lLoguinho"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/loguinho_white"
tools:ignore="ContentDescription" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/lMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="1"
android:paddingLeft="16dp"
android:paddingTop="24dp"
android:paddingRight="16dp"
android:paddingBottom="16dp">
<ImageView
android:id="@+id/imgMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/menu_white"
tools:ignore="ContentDescription" />
</RelativeLayout>
</RelativeLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/lFooter"
android:layout_below="@+id/lTop"
android:background="@color/colorPrimaryOn2"
android:scrollbars="vertical">
<br.com.xpto.onboarding.components.ContentView
android:id="@+id/lContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGold"
android:orientation="vertical">
</br.com.xpto.onboarding.components.ContentView>
</android.support.v4.widget.NestedScrollView>
<br.com.xpto.onboarding.components.FooterView
android:id="@+id/lFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/blue">
"THE CHILD VIEW GOES HERE AFTER TOUCH EVENT"
</br.com.xpto.onboarding.components.FooterView>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:alpha="0"
android:indeterminate="true"
android:indeterminateTint="@color/colorEditTextHint" />
</RelativeLayout>
大孩子视野
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lContentChoice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGrayButton">
<TextView
android:id="@+id/labelPerguntaAux"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" "
android:textSize="17dp"
android:visibility="invisible" />
<TextView
android:id="@+id/labelPergunta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:focusableInTouchMode="true"
android:paddingStart="24dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textColor="@color/colorPrimaryOn"
android:textSize="17dp" />
<RelativeLayout
android:id="@+id/lBotoes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/labelPergunta"
android:background="@color/colorGrayButton"
android:paddingStart="16dp"
android:paddingTop="34dp"
android:paddingEnd="16dp"
android:paddingBottom="34dp">
<LinearLayout
android:id="@+id/lBtTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/btChoice1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_weight="0.5"
android:background="@drawable/bg_rounded_on_red"
android:gravity="center"
android:padding="16dp"
android:text="CNH"
android:textColor="@color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="@+id/btChoice2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="0.55"
android:background="@drawable/bg_rounded_on_red"
android:gravity="center"
android:padding="16dp"
android:text="RG"
android:textColor="@color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lBtTop"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<TextView
android:id="@+id/btChoice3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_weight="0.7"
android:background="@drawable/bg_rounded_on_red"
android:gravity="center"
android:padding="16dp"
android:text="RNE"
android:textColor="@color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="@+id/btChoice4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="0.5"
android:background="@drawable/bg_rounded_on_red"
android:gravity="center"
android:padding="16dp"
android:text="Funcional"
android:textColor="@color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
小子视图
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGrayButton">
<TextView
android:id="@+id/labelPerguntaAux"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" "
android:textSize="17dp"
android:visibility="invisible" />
<TextView
android:id="@+id/labelPergunta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:focusableInTouchMode="true"
android:paddingStart="24dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textColor="@color/colorPrimaryOn"
android:textSize="17dp"
android:visibility="visible" />
<RelativeLayout
android:id="@+id/lConteudo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/labelPergunta"
android:background="@color/colorGrayButton"
android:paddingStart="64dp"
android:paddingTop="34dp"
android:paddingEnd="64dp"
android:paddingBottom="34dp">
<TextView
android:id="@+id/btFinal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:background="@drawable/bg_rounded_on_red"
android:gravity="center"
android:padding="16dp"
android:text="Próxima etapa"
android:textColor="@color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:alpha="0"
android:indeterminate="true"
android:indeterminateTint="@color/colorEditTextHint" />
</RelativeLayout>
</RelativeLayout>
大儿童观课
public class ChoiceDocRespostaView extends Pergunta {
private String choice1, choice2, choice3, choice4;
private TextView textPergunta, labelPerguntaAux;
private RelativeLayout lContent;
private TextView btChoice4;
public ChoiceDocRespostaView(Context context, Ask ask, String choice1, String choice2, String choice3, String choice4) {
super(context);
this.choice1 = choice1;
this.choice2 = choice2;
this.choice3 = choice3;
this.choice4 = choice4;
setView(this);
setPergunta(ask.getAsk());
setResposta(ask.getAnswer());
init(context);
}
public ChoiceDocRespostaView(Context context) {
super(context);
init(context);
}
public ChoiceDocRespostaView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public ChoiceDocRespostaView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
public void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.on_choice_resposta_doc, this);
final TextView btChoice1 = findViewById(R.id.btChoice1);
TextView btChoice2 = findViewById(R.id.btChoice2);
TextView btChoice3 = findViewById(R.id.btChoice3);
btChoice4 = findViewById(R.id.btChoice4);
textPergunta = findViewById(R.id.labelPergunta);
labelPerguntaAux = findViewById(R.id.labelPerguntaAux);
lContent = findViewById(R.id.lContentChoice);
btChoice1.setText(choice1);
btChoice2.setText(choice2);
btChoice3.setText(choice3);
btChoice4.setText(choice4);
lContent.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
textPergunta.setText(getPergunta());
refazerFooter();
lContent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
btChoice1.setOnClickListener(v -> {
setResposta(choice1);
if (getActivityCadastroFotoReturn() != null) {
getActivityCadastroFotoReturn().returnFoto(choice1);
} else if (getPendenciaDocumentoReturn() != null) {
getPendenciaDocumentoReturn().returnEditFoto(choice1);
} else {
getActivityPerguntaFotoReturn().returnEditFoto(choice1);
}
});
btChoice2.setOnClickListener(v -> {
setResposta(choice2);
if (getActivityCadastroFotoReturn() != null) {
getActivityCadastroFotoReturn().returnFoto(choice2);
} else if (getPendenciaDocumentoReturn() != null) {
getPendenciaDocumentoReturn().returnEditFoto(choice2);
} else {
getActivityPerguntaFotoReturn().returnEditFoto(choice2);
}
});
btChoice3.setOnClickListener(v -> {
setResposta(choice3);
if (getActivityCadastroFotoReturn() != null) {
getActivityCadastroFotoReturn().returnFoto(choice3);
} else if (getPendenciaDocumentoReturn() != null) {
getPendenciaDocumentoReturn().returnEditFoto(choice3);
} else {
getActivityPerguntaFotoReturn().returnEditFoto(choice3);
}
});
btChoice4.setOnClickListener(v -> {
setResposta(choice4);
if (getActivityCadastroFotoReturn() != null) {
getActivityCadastroFotoReturn().returnFoto(choice4);
} else if (getPendenciaDocumentoReturn() != null) {
getPendenciaDocumentoReturn().returnEditFoto(choice4);
} else {
getActivityPerguntaFotoReturn().returnEditFoto(choice4);
}
});
}
@Override
public void refazerFooter() {
if (getActivityPerguntaFotoReturn() != null) {
ViewGroup.LayoutParams layoutParams = getActivityPerguntaFotoReturn().bind.lFooter.getLayoutParams();
layoutParams.height = UtilOnboarding.getTamanho(getActivityPerguntaFotoReturn(), 1, 4);
getActivityPerguntaFotoReturn().bind.lFooter.setLayoutParams(layoutParams);
getActivityPerguntaFotoReturn().bind.lFooter.forceLayout();
getActivityPerguntaFotoReturn().bind.lFooter.getParent().requestLayout();
//getActivityPerguntaFotoReturn().bind.lFooter.setMinimumHeight(layoutParams.height);
//LayoutWrapContentUpdater.wrapContentAgain(this, true);
//invalidate();
//getActivityPerguntaFotoReturn().bind.lFooter.update
//getActivityPerguntaFotoReturn().bind.lFooter.requestLayout();
/*getActivityPerguntaFotoReturn().bind.lFooter.*/
} else if (getActivityCadastroFotoReturn() != null) {
ViewGroup.LayoutParams layoutParams = getActivityCadastroFotoReturn().bind.lFooter.getLayoutParams();
layoutParams.height = UtilOnboarding.getTamanho(getActivityCadastroFotoReturn(), 1, 4);
getActivityCadastroFotoReturn().bind.lFooter.setLayoutParams(layoutParams);
} else if (getPendenciaDocumentoReturn() != null) {
ViewGroup.LayoutParams layoutParams = getPendenciaDocumentoReturn().bind.lFooter.getLayoutParams();
layoutParams.height = UtilOnboarding.getTamanho(getPendenciaDocumentoReturn(), 1, 4);
getPendenciaDocumentoReturn().bind.lFooter.setLayoutParams(layoutParams);
}
}
}
Pergunta类
public class Pergunta extends RelativeLayout {
private String pergunta;
private String resposta;
private View view;
private BasePerguntaActivity activityReturn;
private OnPerguntaDadosBancariosActivity activityDadosBancariosReturn;
private BaseCadastroAnimationActivity activityCadastroReturn;
private BasePerguntaActivity activity;
private BaseCadastroAnimationActivity activityCadastro;
private OnDocumentosActivity activityFotoReturn;
private OnPerguntaDocumentosActivity activityPerguntaFotoReturn;
private OnEnderecoPendenciaActivity activityPendenciaFotoReturn;
private OnPendenciaDocumentosActivity activityPendenciaDocumentoReturn;
public View getView() {
return view;
}
public void setView(View view) {
this.view = view;
}
public Pergunta(Context context) {
super(context);
}
public Pergunta(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Pergunta(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public String getPergunta() {
return pergunta;
}
public void setPergunta(String pergunta) {
this.pergunta = pergunta;
}
public String getResposta() {
return resposta;
}
public void setResposta(String resposta) {
this.resposta = resposta;
}
public BasePerguntaActivity getActivityReturn() {
return activityReturn;
}
public void setActivityReturn(BasePerguntaActivity activityReturn) {
this.activityReturn = activityReturn;
}
public void setActivityCadastroReturn(BaseCadastroAnimationActivity activityCadastroReturn) {
this.activityCadastroReturn = activityCadastroReturn;
}
public BaseCadastroAnimationActivity getActivityCadastroReturn() {
return activityCadastroReturn;
}
public void setActivityCadastroFotoReturn(OnDocumentosActivity activityFotoReturn) {
this.activityFotoReturn = activityFotoReturn;
}
public OnDocumentosActivity getActivityCadastroFotoReturn() {
return activityFotoReturn;
}
public void setActivityPerguntaFotoReturn(OnPerguntaDocumentosActivity activityPerguntaFotoReturn) {
this.activityPerguntaFotoReturn = activityPerguntaFotoReturn;
}
public OnPerguntaDocumentosActivity getActivityPerguntaFotoReturn() {
return activityPerguntaFotoReturn;
}
public void setPendenciaDocumentoReturn(OnPendenciaDocumentosActivity activityPendenciaDocumentoReturn) {
this.activityPendenciaDocumentoReturn = activityPendenciaDocumentoReturn;
}
public OnPendenciaDocumentosActivity getPendenciaDocumentoReturn() {
return activityPendenciaDocumentoReturn;
}
public void setPendenciaFotoReturn(OnEnderecoPendenciaActivity activityPendenciaFotoReturn) {
this.activityPendenciaFotoReturn = activityPendenciaFotoReturn;
}
public OnEnderecoPendenciaActivity getPendenciaFotoReturn() {
return activityPendenciaFotoReturn;
}
public BasePerguntaActivity getActivity() {
return activity;
}
public void setActivity(BasePerguntaActivity activity) {
this.activity = activity;
}
public void setActivityCadastro(BaseCadastroAnimationActivity activity) {
this.activityCadastro = activity;
}
public BaseCadastroAnimationActivity getActivityCadastro() {
return activityCadastro;
}
public void refazerFooter(){}
}
有人对此问题有答案吗?
欢呼 古斯