android滾動顯示
㈠ 怎麼在android中出現滾動界面
使用ScrollView即可。
例如:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fadingEdge="vertical"
>
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:padding="10dip"
android:scrollbars="vertical"
>
注意的是:ScrollView也是一個layout布局,可以讓它的內容數據顯示不下的時候出現滾動條。但是不能在ScrollView中放置多個組件,Scrollview只能包裹一個子元素。可以在Scrollview中放置一個LinearLayout或其他layout來放置更多組件(Layout可以嵌套的)。
㈡ 安卓系統桌面循環滾動桌面設置的
1、手機設置」的「輔助功能」中有選擇是否「桌面循環」。
2、在原生的android源碼上添加這一功能。
思路:先把界面做出來,再將是否選擇的值存到系統的(adb shell進入)data/data/com.android.providers.settings/databases/settings.db資料庫中的system表中,
然後在Launch2的源碼中取得資料庫中是否選擇循環桌面來執行相關代碼。
先做UI:
在settings源碼中的accessibility_settings.xml文件中添加一個checkbox:
java代碼
android:key="launch_repeat"
android:title="@string/launch_repeat_title"
android:persistent="false"/>
在settings源碼的res中添加相關的代碼:
在values/string.xml中添加(英文顯示):
Launch Repeat
在values-zh-rCN/string.xml中添加(中文顯示):
"循環桌面"
在settings源碼的AccessibilitySettings.java中的OnCreate中添加:
java代碼
/*****************************************/
mLaunchRepeat=(CheckBoxPreference) findPreference(
LAUNCH_REPEAT);
int LaunchRepeat=Settings.System.getInt(this.getContentResolver(),
"launch_repeat",0);//取出是否被選擇
if(LaunchRepeat==1)//如果被選擇,那麼下次打開setting時就勾選
mLaunchRepeat.setChecked(true);
else
mLaunchRepeat.setChecked(false);//如果沒被選擇,那麼下次打開setting時就不勾選
/*****************************************/
當然還要定義幾個量:
private final String LAUNCH_REPEAT =
"launch_repeat";
private CheckBoxPreference mLaunchRepeat;
在onPreferenceTreeClick函數中添加:
java代碼
//add by xxnan
if(LAUNCH_REPEAT.equals(key))
{
Settings.System.putInt(getContentResolver(),
"launch_repeat",
((CheckBoxPreference) preference).isChecked()?
1:0);//將是否選擇存到系統的system表中
}
//add by xxnan
如果做好了之後當點擊選擇「桌面循環時」可以到(adb shell進入)data/data/com.android.providers.settings/databases下的settings.db資料庫(sqlite3 settings.db)的system
表中看到33|launch_repeat|1(select * from system;)。
到這里就完成了將數據存到系統system表中以及UI,接下來就是在Launch2源碼中去取這個值(是否循環)。
到Launcher2源碼中去找到Workspace.java文件,在裡面有相應的修改:
在onTouchEvent中,之前有修改循環,如下:
java代碼
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_SCROLLING) {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
final int velocityX = (int)
velocityTracker.getXVelocity(mActivePointerId);
final int screenWidth = getWidth();
final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth;
final float scrolledPos = (float) mScrollX / screenWidth;
Log.i("velocityX","velocityX="+velocityX+"whichScreen="+whichScreen);
/***********************************************/
//modifided by xxnan
if (velocityX > SNAP_VELOCITY) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
Log.i("numscreen","numscreen="+mCurrentScreen);
/* final int bound = scrolledPos < whichScreen ?
( (mCurrentScreen+ getChildCount()) - 1 )% getChildCount():
mCurrentScreen;*/
final int bound =( (mCurrentScreen+ getChildCount()) - 1 )% getChildCount()
;
Log.i("numscreen","bound="+bound);
snapToScreen( bound, velocityX, true);
} else if (velocityX < -SNAP_VELOCITY ) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
/*final int bound = scrolledPos > whichScreen ?
( mCurrentScreen + 1 )% getChildCount(): mCurrentScreen;*/
final int bound = ( mCurrentScreen + 1 )% getChildCount() ;
snapToScreen(bound, velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}
/***********************************************/
//下面是原生代碼
/*if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
final int bound = scrolledPos < whichScreen ?
mCurrentScreen - 1 : mCurrentScreen;
snapToScreen(Math.min(whichScreen, bound), velocityX, true);
} else if (velocityX < -SNAP_VELOCITY && mCurrentScreen <
getChildCount() - 1) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
final int bound = scrolledPos > whichScreen ?
mCurrentScreen + 1 : mCurrentScreen;
snapToScreen(Math.max(whichScreen, bound), velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}*/
}
mTouchState = TOUCH_STATE_REST;
mActivePointerId = INVALID_POINTER;
releaseVelocityTracker();
break;
那麼就要在修改的地方加一個判斷,如果system中取得的值是1,就可以循環,如果是0,就不能。
代碼修改如下:
java代碼
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_SCROLLING) {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
final int velocityX = (int)
velocityTracker.getXVelocity(mActivePointerId);
final int screenWidth = getWidth();
final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth;
final float scrolledPos = (float) mScrollX / screenWidth;
Log.i("velocityX","velocityX="+velocityX+"whichScreen="+whichScreen);
/***********************************************/
//modifided by xxnan 2013-1-9
launch_repeat=Settings.System.getInt(mContext.getContentResolver(),
"launch_repeat",0);//取出system表中「launch_repeat」的值
Log.i(" launch_repeat"," launch_repeat="+ launch_repeat);
if(launch_repeat==1)//如果是1,就循環,也就是之前已經改好的
{
if (velocityX > SNAP_VELOCITY) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
Log.i("numscreen","numscreen="+mCurrentScreen);
/* final int bound = scrolledPos < whichScreen ?
( (mCurrentScreen+ getChildCount()) - 1 )% getChildCount():
mCurrentScreen;*/
final int bound =( (mCurrentScreen+ getChildCount()) - 1 )% getChildCount()
;
Log.i("numscreen","bound="+bound);
snapToScreen( bound, velocityX, true);
} else if (velocityX < -SNAP_VELOCITY ) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
/*final int bound = scrolledPos > whichScreen ?
( mCurrentScreen + 1 )% getChildCount(): mCurrentScreen;*/
final int bound = ( mCurrentScreen + 1 )% getChildCount() ;
snapToScreen(bound, velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}
}
else//如果是0,那麼就是原生代碼,不循環
{
if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
final int bound = scrolledPos < whichScreen ?
mCurrentScreen - 1 : mCurrentScreen;
snapToScreen(Math.min(whichScreen, bound), velocityX, true);
} else if (velocityX < -SNAP_VELOCITY && mCurrentScreen <
getChildCount() - 1) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
final int bound = scrolledPos > whichScreen ?
mCurrentScreen + 1 : mCurrentScreen;
snapToScreen(Math.max(whichScreen, bound), velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}
}
/***********************************************/
//下面是原生代碼
/*if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
final int bound = scrolledPos < whichScreen ?
mCurrentScreen - 1 : mCurrentScreen;
snapToScreen(Math.min(whichScreen, bound), velocityX, true);
} else if (velocityX < -SNAP_VELOCITY && mCurrentScreen <
getChildCount() - 1) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
final int bound = scrolledPos > whichScreen ?
mCurrentScreen + 1 : mCurrentScreen;
snapToScreen(Math.max(whichScreen, bound), velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}*/
}
mTouchState = TOUCH_STATE_REST;
mActivePointerId = INVALID_POINTER;
releaseVelocityTracker();
break;
當然這裡面也要定義幾個量,以及導入幾個包:
導入包:
//add by xxnan
import android.content.ContentResolver;//從system表中取數據
import android.provider.Settings;
定義變數:
private int launch_repeat;//取得是否循環的值
到這里就全部修改好了,還有就是編譯一下源碼中的package/apps的Launch2和Settings的源碼,將生成的out/target/。。。/system/app下的
Launch2.apk和Settings.apk替換手機里system/app的這兩個apk就可以了。
㈢ 想在android手機屏幕上實現文字的滾動顯示
Animation ani = AnimationUtil.loadAnimation(R.anim.youranime);
yourWidget.startAnimation(ani);
用xml構造animation請自行查看api手冊..
㈣ Android中這種類似的滾動界面是如何實現的
第一,在布局文件中添加一個Button,單擊Button,彈出菜單 第二,我們給Button添加一個單擊事件popupMenu,接下來,就在java文件中實現該方法。 第三,我們載入了一個menu文件「popupmenu」 第四,別忘了在onCreate方法中初始化Button。
㈤ android textview 怎麼實現文字滾動
TextView實現文字滾動需要以下幾個要點:
1.文字長度長於可顯示範圍:android:singleLine="true"
2.設置可滾到,或顯示樣式:android:ellipsize="marquee"
3.TextView只有在獲取焦點後才會滾動顯示隱藏文字,因此需要在包中新建一個類,繼承TextView。重寫isFocused方法,這個方法默認行為是,如果TextView獲得焦點,方法返回true,失去焦點則返回false。跑馬燈效果估計也是用這個方法判斷是否獲得焦點,所以把它的返回值始終設置為true。ellipsize屬性
設置當文字過長時,該控制項該如何顯示。有如下值設置:」start」—–省略號顯示在開頭;」end」——省略號顯示在結尾;」middle」—-省略號顯示在中間;」marquee」 ——以跑馬燈的方式顯示(動畫橫向移動)marqueeRepeatLimit屬性
在ellipsize指定marquee的情況下,設置重復滾動的次數,當設置為marquee_forever時表示無限次。focusable屬性
能否獲得焦點,同樣focusableInTouchMode應該是滑動時能否獲得焦點
㈥ Android scrollview滾動條顯示不出來怎麼辦
正好也遇到這個問題,剛看到的分享下 android:background 設置背景色/背景圖片。可以通過以下兩種方法設置背景為透明:」@android:color/transparent」和」@null」。注意TextView默認是透明的,不用寫此屬性,但是Buttom/ImageButton/ImageView想透
㈦ 》android 編程中如何實現頁面滾動...是用ScrollView嗎 具體怎麼實現...
1L正解。就是在你現在的xml裡面所有的控制項外麵包裹一層ScrollView,這樣ScrollView裡面的所有顯示的內容都是可以滾動查看的。
㈧ 如何在android中實現,一幅一幅圖片 通過手勢滾動顯示,並且可以兩個手指觸控來縮放圖片
總得一句話要重寫onTouchEvent
1.手勢滾動有很多方法:
可用viewpager實現view的左右滑屏,也可以用ViewFlipper,還有笨方法就是一個imageview,獲取按下抬起坐標,判斷左滑右滑,然後set另一張圖片進去。
2.縮放也有很多做法
正統的做法是把imageview的屬性scaleType設置為matrix(矩陣),然後獲取滑動手勢,來操作矩陣獲得縮放的效果
㈨ android 如何讓多條數據在一個textview中垂直滾動顯示
Android中我們為了實現文本的滾動可以在ScrollView中嵌入一個TextView,其實TextView自己也可以實現多行滾動的,畢竟ScrollView必須只能有一個直接的子類布局。只要在layout中簡單設置幾個屬性就可以輕松實現
<TextView
android:id="@+id/tvCWJ"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"<!--垂直滾動條-->
android:singleLine="false"<!--實現多行-->
android:maxLines="15"<!--最多不超過15行-->
android:textColor="#FF0000"
/>
當然我們為了讓TextView動起來,還需要用到TextView的setMovementMethod方法設置一個滾動實例,代碼如下:
TextViewtvAndroid123=(TextView)findViewById(R.id.tvCWJ);
tvAndroid123.setMovementMethod(ScrollingMovementMethod.getInstance());//Android開發網提示相關的可以查看SDK中android.text.method分支了解更多
㈩ android LinearLayout滾動條自動顯示
這樣的功能不適合用LinearLayout來實現,應當使用 ScrollView。
追蹤最末尾的方法是,每次ScroolView的內容改變時,都執行一下這一句:
scrollText.post(new Runnable() {
public void run() {
scrollText.fullScroll(ScrollView.FOCUS_DOWN);
}
});
這里假設這個ScroolView是scrollText。