我有注册页面,因为存在四个EditText,当我点击第三个EditText时,必须显示一个LinearLayout(假设密码指南),同时应该滚动总布局以查看所有指南。当其他EditText( 1,2或4)得到关注这个LinearLayout(密码指南)应该关闭。我尝试了很多,我搜索了很多,没有解决方案适合我,请帮助我。为了理解我做了小项目,请观看。
public class MainActivity extends AppCompatActivity {
private EditText mEditText1,mEditText2,mEditText3,mEditText4;
private LinearLayout ll,root;
ScrollView mScrollView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
root = (LinearLayout) findViewById(R.id.ll_linear_layout);
ll = (LinearLayout) findViewById(R.id.ll);
mEditText1 = (EditText) findViewById(R.id.et1);
mEditText2 = (EditText) findViewById(R.id.et2);
mEditText3 = (EditText) findViewById(R.id.et3);
mEditText4 = (EditText) findViewById(R.id.et4);
mEditText1.setOnFocusChangeListener(mListener1);
mEditText2.setOnFocusChangeListener(mListener2);
mEditText3.setOnFocusChangeListener(mLayoutExtract);
mEditText4.setOnFocusChangeListener(mListener4);
mScrollView = new ScrollView(this);
}
View.OnFocusChangeListener mListener1 = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if (b) {
} else {
}
}
};
View.OnFocusChangeListener mListener2 = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if (b) {
} else {
}
}
};
View.OnFocusChangeListener mLayoutExtract = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if (b) {
ll.setVisibility(View.VISIBLE);
} else {
ll.setVisibility(View.GONE);
}
}
};
View.OnFocusChangeListener mListener4 = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if (b) {
} else {
}
}
}};
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/ll_linear_layout"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:layout_marginTop="200dp"
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="first name"/>
<EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
<EditText
android:id="@+id/et3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
<LinearLayout
android:id="@+id/ll"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="75dp"
android:textColor="#000000"
android:text="Hidable text"/>
</LinearLayout>
<EditText
android:id="@+id/et4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
答案 0 :(得分:1)
试试这个
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/ll_linear_layout"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:layout_marginTop="200dp"
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="first name"/>
<EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
<EditText
android:id="@+id/et3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
<LinearLayout
android:id="@+id/ll"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="75dp"
android:textColor="#000000"
android:text="Hidable text"/>
</LinearLayout>
<EditText
android:id="@+id/et4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
</LinearLayout>
</ScrollView>
尝试使用android:windowSoftInputMode =“AdjustResize”在你的Manifest中,你正在解析你的活动,如下面的代码
<activity
android:name=".YourActivity"
android:parentActivityName="XXX.XXX.XXXX"
android:windowSoftInputMode="AdjustResize" />