<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false">
<LinearLayout
android:id="@+id/layout"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical"/>
</ScrollView>
public class ScrollViewActivity extends Activity
{
private LinearLayout layout;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_scrollview);
layout = (LinearLayout) findViewById(R.id.layout);
for(int i = 0; i < 8; i++)
{
// 通过资源文件来获得指定一个Drawable对象
Drawable drawable = getResources().getDrawable(R.drawable.kk_hero);
ImageView imageView = new ImageView(this);
imageView.setImageDrawable(drawable);
layout.addView(imageView);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false">
<LinearLayout
android:id="@+id/layout"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical"/>
</ScrollView>
public class HttpUtils
{
/**
* 访问服务器端的内容
* @param path 访问的url地址
* @param encode 编码方式
* @return 返回String类型的值
*/
public static String getDataFromServer(String path, String encode)
{
String result = "";
HttpClient httpClient = new DefaultHttpClient();
try
{
HttpPost httpPost = new HttpPost(path);
HttpResponse httpResponse = httpClient.execute(httpPost);
if (httpResponse != null && httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
result = EntityUtils.toString(httpResponse.getEntity(), "utf-8");
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
httpClient.getConnectionManager().shutdown();
}
return result;
}
}
public class ScrollViewActivity extends Activity
{
private LinearLayout layout;
private ProgressDialog dialog;
private TextView textView;
private final String PATH = "http://172.25.152.34:8080/httptest/news.html";
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_scrollview);
dialog = new ProgressDialog(this);
dialog.setTitle("提示信息");
dialog.setMessage("loading......");
dialog.setCancelable(false);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
layout = (LinearLayout) findViewById(R.id.layout);
textView = new TextView(this);
layout.addView(textView);
new MyTask().execute(PATH);
}
public class MyTask extends AsyncTask<String, Void, String>
{
@Override
protected void onPreExecute()
{
dialog.show();
}
@Override
protected String doInBackground(String... params)
{
String result = HttpUtils.getDataFromServer(params[0], "utf-8");
return result;
}
@Override
protected void onPostExecute(String s)
{
// Html类的fromHtml方法可以处理一个Html的字符串文本,这样就可以根据Html的标签在手机上展示其样式
Spanned spanned = Html.fromHtml(s);
textView.setText(spanned);
// 给TextView设置一个方法,传一个LinkMovementMethod对象进去,这样当文本中如果有href链接时,系统会自动打开浏览器跳转到该href上
textView.setMovementMethod(new LinkMovementMethod());
dialog.dismiss();
}
}
}
public static Spanned fromHtml (String source) Returns displayable styled text from the provided HTML string. Any <img> tags in the HTML will display as a generic replacement image which your program can then go through and replace with real images. This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有