当孩子聚焦时,Scrollview会滚动到原点

时间:2018-01-02 08:23:22

标签: android android-scrollview

我有View (RelativeLayout),由ScrollView管理。

该视图包含EditText。每当EditText集中注意力时,通过点击或requestFocus()调用ScrollViewScrollView就会跳回到最高位置。怎样才能使public class MyView extends RelativeLayout{ public MyView(Context context){ super(context); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int)(4 * 600)); lp.height = (int)(3000); lp.width = ViewGroup.LayoutParams.MATCH_PARENT; setLayoutParams(lp); setBackgroundColor(0xddeeeeee); EditText editText = new EditText(getContext()); editText.setLayoutParams(new ViewGroup.LayoutParams(150, 150)); editText.setX(200); editText.setY(400); editText.setBackgroundColor(0xff0000aa); addView(editText); } 保持在实际位置? 代码如下:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final LinearLayout listView = (LinearLayout) findViewById(R.id.project_list);
    ScrollView scrollView = new ScrollView(getApplicationContext());
    MyView view = new MyView(getApplicationContext());
    scrollView.addView(view);
    listView.addView(scrollView);
}

和活动:

func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation

2 个答案:

答案 0 :(得分:0)

实际上,如果你希望你的整个布局比你应该使用的那样:

<强> SOFT_INPUT_ADJUST_PAN

含义:

getActivity().getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

答案 1 :(得分:0)

android:focusableInTouchMode="true"
android:focusable="true"

将这些行添加到Scroll View中的Relative Layout