gpt4 book ai didi

java - 当特定的 EditText 具有焦点时滚动整个页面?

转载 作者:行者123 更新时间:2023-11-30 10:23:16 26 4
gpt4 key购买 nike

我有注册页面,因为存在四个 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"/>

最佳答案

试试这个

<?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>

试试这个在你的 list 中使用 android:windowSoftInputMode="AdjustResize"你正在 decraing YOur Activity 就像下面的代码一样

<activity
android:name=".YourActivity"
android:parentActivityName="XXX.XXX.XXXX"
android:windowSoftInputMode="AdjustResize" />

关于java - 当特定的 EditText 具有焦点时滚动整个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47097177/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com