Android UI details (edittext, listview, fill screen, etc.), androidedittext

Source: Internet
Author: User

Android UI details (edittext, listview, fill screen, etc.), androidedittext

This week, the company's App is about to be released. According to the UI requirements, the UI interaction is adjusted again. Summary of the small knowledge details.

I. Control focus acquisition

mText.setText("gfgss");mText.setFocusable(true);
The input box in xml sets the default retrieval focus. <requestFocus/>
        <AutoCompleteTextView            android:layout_width="0dp"            android:layout_height="match_parent">            <requestFocus />        </AutoCompleteTextView>

2. How to place the cursor at the end of the text in EditText?

mText.setSelection(mText.getText().length());

Iii. Problem of setting the Input Method for activity. If a suspended layout is involved, use adjustPan to cover the input box.

The stateHidden input method does not pop up during activity startup. It is configured in activity.

android:windowSoftInputMode="stateHidden|adjustPan"


4. Set the split line of layout or the split line of listview
android:divider="@drawable/shape_divider"android:showDividers="beginning|middle|end" 

5. Remove the listview scrolling display
android:scrollbars="none"


6. Remove the split line of listview.
android:divider="@null"

7. Remove the selected color by default.
(1) set the backgroudcolor attribute of layout.
(2)
android:focusable="false"android:focusableInTouchMode="false"android:cacheColorHint="#00000000"android:listSelector="#00000000"

8. Replace the default selected color of listview.
Set the listSelector attribute of listivew.

9. intelligently fill the remaining screens
Sometimes the following two statements are better than android: layout_width = "match_parent. More intelligent filling of remaining screens

android:layout_height="0dp"android:layout_weight="1" 

10. Use the ScrollView attribute fillViewport to solve the problem that the android layout cannot be full screen.
When the elements in ScrollView want to fill up ScrollView, "fill_parent" is useless and must be set for ScrollView: android: fillViewport = "true ".
When ScrollView does not have fillVeewport = "true", the elements (such as LinearLayout) in the ScrollView are calculated according to wrap_content (whether or not it sets "fill_parent "), if fill_parent is set for the LinearLayout element, it is useless because LinearLayout depends on the element in it and the element in it depends on LinearLayout. therefore, fill_parent is set in the element, which is also calculated as wrap_content.


11. Click a part other than the dialog box to end the activity.

public boolean onTouchEvent(MotionEvent event) {if (MotionEvent.ACTION_OUTSIDE == event.getAction()) {finish();return true;}return super.onTouchEvent(event);}


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.