如何在我的佈局中動態添加滾動視圖?一旦我得到那個scrollview添加我想添加一個linearlayout裏面,所以我現在可以在該linearlayout中添加控件?動態添加滾動視圖在滾動視圖中的佈局和線性佈局
4
A
回答
5
5
我希望它會幫助你。
試試這個代碼...
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout rl=(RelativeLayout)findViewById(R.id.rl);
ScrollView sv = new ScrollView(this);
sv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
ll.setOrientation(1);
sv.addView(ll);
for(int i = 0; i < 20; i++)
{
Button b = new Button(this);
b.setText("Button "+i);
ll.addView(b);
}
rl.addView(sv);
/* If you want to set entire layout as dynamically, then remove below lines in program :
* setContentView(R.layout.activity_main);
* RelativeLayout rl=(RelativeLayout)findViewById(R.id.rl);
* rl.addView(sv);
*
* And Add below line :
* this.setContentView(sv);
*/
}
-1
試試這個它會工作:
TextView tv = new TextView(this);
tv.setText(msg);
tv.setMovementMethod(new ScrollingMovementMethod());
setContentView(tv);
-1
你可以用滾動型內小部件。這裏有一個簡單的例子:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txt"/>
</LinearLayout>
</ScrollView>
如果你想這樣做代碼:
ScrollView sv = new ScrollView(this);
//Add your widget as a child of the ScrollView.
sv.addView(wView);
相關問題
- 1. 在滾動視圖中動態添加線性佈局
- 2. 將滾動視圖添加到佈局
- 3. 滾動視圖滾動佈局內?
- 4. 中添加許多線性佈局滾動視圖
- 5. 的Xcode - 滾動視圖 - 自動佈局
- 6. 添加滾動視圖後相對佈局不滾動
- 7. mono for android - 動態添加布局到滾動視圖
- 8. 滾動視圖與自動佈局
- 9. 滾動視圖滾動列表視圖不是佈局
- 10. 將視圖添加到滾動視圖的底部佈局
- 11. 滾動視圖中的全屏佈局
- 12. 以編程方式添加視圖(線性)佈局(即滾動視圖內)
- 13. TableLayout&滾動視圖拉伸在佈局
- 14. android textview scrollview在佈局滾動視圖
- 15. 滾動視圖內部的水平和垂直線性佈局
- 16. 在線性佈局中動態添加視圖
- 17. 滾動查看不滾動子視圖在自動佈局
- 18. 滾動視圖不工作的佈局
- 19. 機器人XML滾動視圖和線性佈局問題
- 20. 如何在佈局中添加完整的滾動視圖?
- 21. 線性佈局不滾動
- 22. 設置水平滾動視圖佈局
- 23. 滾動視圖相對佈局問題
- 24. android佈局 - 滾動視圖不顯示
- 25. 問題與滾動視圖內佈局
- 26. Android佈局 - 雙水平滾動視圖
- 27. 滾動圓形佈局集合視圖
- 28. 可滾動佈局重疊視圖
- 29. 滾動後滾動列表視圖中的佈局
- 30. iOS 6自動佈局滾動視圖不滾動兩個表