2010-04-28 32 views
2

我在main.xml中創建了一個TextView。在我的app.java中,我根據用戶點擊屏幕的位置動態定位TextView。我遇到的問題是,當我調用myTextView.setPadding(100,100,0,0)時,它將移動TextView的實際文本,但不移動TextView的彩色背景。當TextView.Padding更改時Android TextView的背景不移動

想法?

回答

2

填充隻影響視圖的內容,您可以將視圖嵌入到LinearLayout中,並更改LinearLayout的填充以移動TextView。

0

如果您想移動整個內容,則可能需要使用邊距。

0

您可以使用動畫來移動視圖。

Animation a = new TranslateAnimation((oldPos), 
       newPos, 0.0f, 0.0f); 
     a.setDuration(300); 
     a.setStartOffset(100); 
     a.setRepeatMode(Animation.ABSOLUTE); 
     a.setFillAfter(true); 

     a.setInterpolator(AnimationUtils.loadInterpolator(this.getContext(), 
         android.R.anim.accelerate_decelerate_interpolator)); 

View.startAnimation(a);