Android UI 問題隨筆

最近做個demo,涉及到一些UI,總結如下:

1.需要做一個可以多行顯示log的textview,之前打算通過設置控件屬性來實現,但是試了很多辦法似乎不行,最後的辦法如下:

    <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:id="@+id/textView_log"

                android:gravity="top"

                android:maxLines="20"

                android:singleLine="false" />

在打印每一行log之前:

    TextView log_testView =(TextView)findViewById(R.id.textView_log);

    String log = log_testView.getText().toString();

    log_testView.setText("from:" + from +" msg:" + msg + "\n\r" + log);

這樣顯示內容就從頂部刷新了。


2.activity起來以後焦點總是在第一個textedit控件,並且彈出輸入面板,在mainfest.xml中相應<activity段加入:android:windowSoftInputMode="adjustResize|stateHidden" 可以不彈出輸入面板,但是焦點仍然在第一個textedit控件,通過添加如下代碼在activity的oncreate(),使焦點設置在上面的textview:

      TextView log_textView = (TextView)findViewById(R.id.textView_log);

        log_textView.setFocusable(true);

        log_textView.setFocusableInTouchMode(true);

        log_textView.requestFocus();




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章