我有一个问题,我有一个包含一些元素的片段。我在底部有按钮(signup_step_buttons)我希望它们保持在键盘的顶部。但是,当我setVisibility VISIBLE
对所有元素 adjustResize 工作时,但当我setVisibility GONE
(到 backStep & validForm 时)。当键盘出现时,布局不适应......所以我发现问题(似乎是布局中元素的可见性)但我不知道如何解决它...
修改:问题来自setVisibility
,无论设置的值是什么......就在我调用它时, adaptResize 不会被应用。
我的片段布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/Aidodys.Activity.AuthActivity.SignUp">
<RelativeLayout
android:id="@+id/signup_step_top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<ImageView
android:id="@+id/sign_up_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:src="@drawable/ic_close_light_cross"
android:padding="@dimen/padding_signup_close_step"/>
<ImageView
android:id="@+id/signup_step_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/sign_up_close"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/signup_valid_form"
android:layout_above="@+id/signup_step_buttons"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/signup_valid_form_button"
android:layout_centerHorizontal="true"
style="@style/Aidodys.ButtonWhite.Steps.ValidForm"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/signup_valid_form_button"
android:text="@string/text_agree_cgu"
android:textAlignment="center"
android:textAppearance="@style/Aidodys.Button.Little.Text.Blue"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/signup_step_buttons"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/signup_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
style="@style/Aidodys.ButtonWhite.Steps.Back"
/>
<Button
android:id="@+id/signup_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
style="@style/Aidodys.ButtonWhite.Steps.Next"/>
</RelativeLayout>
<FrameLayout
android:layout_below="@id/signup_step_top_bar"
android:layout_above="@id/signup_valid_form"
android:id="@+id/signup_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"></FrameLayout>
</RelativeLayout>
我的片段类:
public class SignUpFragment extends Fragment {
/**
* Id to identity READ_CONTACTS permission request.
*/
private static final int REQUEST_READ_CONTACTS = 0;
/**
* Keep track of the login task to ensure we can cancel it if requested.
*/
// UI references.
private AidodysRequest aidodysRequest;
private SignUpRequestObject object;
private Button nextStep;
private Button backStep;
private int step;
private int stepMax = 5;
private ImageView stepIndicator;
private StepEmailFragment emailStep;
private StepNameFragment nameStep;
private StepPasswordFragment passwordStep;
private StepCategoryFragment categoryStep;
private StepCountryFragment countryStep;
private RelativeLayout validForm;
private Fragment[] steps = new Fragment[stepMax];
private Drawable[] indicator = new Drawable[stepMax];
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
((AuthActivity)getActivity()).setOnBackPressedListener(new AuthActivity.OnBackPressedListener() {
@Override
public void doBack() {
if (step <= 0) {
getFragmentManager().popBackStack();
} else {
step--;
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (step < 1)
backStep.setVisibility(View.GONE);
stepIndicator.setImageDrawable(indicator[step]);
}
});
}
}
});
return (inflater.inflate(R.layout.fragment_signup, container, false));
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
aidodysRequest = new AidodysRequest(getActivity());
object = new SignUpRequestObject();
indicator[0] = getActivity().getDrawable(R.drawable.ic_step_indicator_1);
indicator[1] = getActivity().getDrawable(R.drawable.ic_step_indicator_2);
indicator[2] = getActivity().getDrawable(R.drawable.ic_step_indicator_3);
indicator[3] = getActivity().getDrawable(R.drawable.ic_step_indicator_4);
indicator[4] = getActivity().getDrawable(R.drawable.ic_step_indicator_5);
stepIndicator = (ImageView)view.findViewById(R.id.signup_step_indicator);
steps[0] = emailStep = new StepEmailFragment();
steps[1] = nameStep = new StepNameFragment();
steps[2] = passwordStep = new StepPasswordFragment();
steps[3] = categoryStep = new StepCategoryFragment();
steps[4] = countryStep = new StepCountryFragment();
step = 0;
stepIndicator.setImageDrawable(indicator[step]);
getFragmentManager()
.beginTransaction()
.replace(R.id.signup_fragment_container, steps[step])
.addToBackStack(null)
.commit();
nextStep = (Button)view.findViewById(R.id.signup_next);
backStep = (Button)view.findViewById(R.id.signup_back);
validForm = (RelativeLayout)view.findViewById(R.id.signup_valid_form);
backStep.setVisibility(View.GONE);
validForm.setVisibility(View.GONE);
emailStep.setOnEmailLookUpResponse(new StepEmailFragment.OnEmailLookUpResponse() {
@Override
public void onSuccess() {
((ISignUpStep)steps[step]).saveData();
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.animator.enter_anim_right, R.animator.exit_anim_left, R.animator.enter_anim_left, R.animator.exit_anim_right)
.replace(R.id.signup_fragment_container, steps[++step])
.addToBackStack(null)
.commit();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
backStep.setVisibility(View.VISIBLE);
stepIndicator.setImageDrawable(indicator[step]);
}
});
}
@Override
public void onFailure() {
}
});
emailStep.setAidodysRequest(aidodysRequest);
nextStep.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((ISignUpStep)steps[step]).checkData() && step < steps.length - 1) {
((ISignUpStep)steps[step]).saveData();
if (step == steps.length - 2) {
validForm.setVisibility(View.VISIBLE);
}
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.animator.enter_anim_right, R.animator.exit_anim_left, R.animator.enter_anim_left, R.animator.exit_anim_right)
.replace(R.id.signup_fragment_container, steps[++step])
.addToBackStack(null)
.commit();
stepIndicator.setImageDrawable(indicator[step]);
}
}
});
backStep.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (step > 0) {
--step;
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (step < 1)
backStep.setVisibility(View.GONE);
if (step == steps.length - 3)
validForm.setVisibility(View.GONE);
stepIndicator.setImageDrawable(indicator[step]);
}
});
getFragmentManager().popBackStack();
}
}
});
}
}