Android的:如何才能使水平滚动的看法? [英] Android : How can make horizontal scroll view?
本文介绍了Android的:如何才能使水平滚动的看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我与Android合作,我想使水平滚动视图在运行时,意味着我想让被Java code这个水平视图。
I am working with android, i want to make horizontal scroll view at run time, means i want to make this horizontal view by java code.
这是我的$ C $的Java的类c
package com.pericent;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
public class HelloTabWidget extends TabActivity {
private String TAG="HelloTabWidget";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
for(int i=0;i<10;i++)
{
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this,ArtistsActivity.class);
Log.v(TAG,"---artist activity is called---");
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(spec);
}
setContentView(tabHost);
}
}
this is activity ArtistActivity which is used in above code to make Tab Widget:-
package com.pericent;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class ArtistsActivity extends Activity {
private String TAG="ArtistsActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview=new TextView(this);
textview.setText("This is Artist Activity");
setContentView(textview);
Log.v(TAG,"---in artist activity---");
}
}
and this is the xml file used in above code:-
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/ic_tab_artists_grey"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/ic_tab_artists_white" />
</selector>
this above xml is used to create tab widget.
this is the output of my above code:-
在我输出的所有部件都显示在屏幕上,但我想显示4个选项卡的时间,和滚动等后必须出示。所以,请建议我我如何添加滚动设施在我的Java code?
in my output all widget are displaying in the screen but i want to display 4 tabs at a time, and other must show after scrolling. So please suggest me how can i add scrollable facility in my java code ?
感谢你在前进。
推荐答案
试试这样
HorizontalScrollView hr=new HorizontalScrollView(this);
hr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
LinearLayout layout=new LinearLayout(this);
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
for(int i=0;i<100;i++){
TextView txt=new TextView(this);
txt.setText("Text " + i );
layout.addView(txt);
}
hr.addView(layout);
mainLayout.addView(hr);
在上面的code I添加文本视图。但你可以添加文本视图任何视图代替。
in the above code i have added text view. but you can add any view instead of text view.
这篇关于Android的:如何才能使水平滚动的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文