**********模拟新浪微博*********


************模拟新浪微博动态*************************

1.项目效果图

主要代码:

  <?xml version="1.0" encoding="utf-8"?>
- < LinearLayout
xmlns:android =" http://schemas.android.com/apk/res/android "
 android:id =" @+id/liner " android:layout_width =" fill_parent "
android:layout_height =" fill_parent " android:orientation =" vertical ">
- < LinearLayout android:layout_width =" match_parent "
android:layout_height =" wrap_content "
 android:padding =" 6dip "
android:background =" #FA8072 ">
  < TextView android:layout_width =" wrap_content "
 android:layout_height =" wrap_content "
android:text =" 新浪微博 - 随便看看 "
android:textSize =" 15sp "
android:textColor =" @android:color/white " />
  </ LinearLayout >
  </ LinearLayout >

 

 

 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dip"
    android:orientation="vertical" >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <ImageView
            android:id="@+id/head_img"
            android:src="@drawable/p1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dip"
            android:layout_alignParentLeft="true"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/head_img"
            android:layout_marginLeft="7dip"
            android:orientation="vertical">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:textColor="#FF6666"
                    android:textSize="16sp"
                    android:typeface="sans"
                    android:textStyle="bold"
                    android:text="赵迪忠"/>
                <TextView
                    android:id="@+id/time"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@id/name"
                    android:layout_alignBottom="@id/name"
                    android:layout_marginLeft="5dip"
                    android:textColor="#696969"
                    android:textSize="12sp"
                    android:text="12:11"/>
               
                 <TextView
                    android:id="@+id/rq"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:textSize="9sp"
                    android:text="123人气"/>
            </RelativeLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dip">
                <TextView
                    android:id="@+id/article"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="50px"
                    android:textSize="12sp"
                    android:text="  我是西伯利亚狼,坑蒙拐骗偷,吃喝嫖赌抽样样不精通。我和比尔盖茨是同行。人生自古谁无死,留取丹心照汗青                 "/>
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
   

</LinearLayout>

2、获取xml资源:在android开发工具中,包bzu、edu中的MainActivity中的getData。

  
  
private void getData () {
// TODO Auto-generated method stub
//获得xml的资源
String names [];
String article [];
TypedArray img ;
int i ;
names = getResources (). getStringArray ( R . array . name );
article = getResources (). getStringArray ( R . array . article );
img = getResources (). obtainTypedArray ( R . array . head_photo );
list_msg = new ArrayList < Messages >();
for ( i = 0 ; i < names . length ; i ++){
Messages message = new Messages ();
message . setImg ( img . getDrawable ( i ));
message . setName ( names [ i ]);
message . setArticel ( article [ i ]);
message . setRq ( "人气:" + String . valueOf ( new Random (). nextInt ( 1000 )));
Date date = new Date ();
SimpleDateFormat simple = new SimpleDateFormat ( "MM-dd" );
message . setTime ( simple . format ( date ));
list_msg . add ( message );
}
}
private void init () {
// TODO Auto-generated method stub
mylistview =( MyListView ) findViewById ( R . id . myListView1 );
// mylistview=new MyListView(this);
// LinearLayout linear=(LinearLayout)MainActivity.this.findViewById(R.id.liner);
// linear.addView(mylistview);
}

3,编写ArticleAdapter类。它继承BaseAdapter类,重写其方法,在getView方法中是加载了list_layout.xml布局,并将List中的每一条数据都对应布局中的控件,这样就显示出来随便看看的数据了

public class ArticleAdapter extends BaseAdapter {
private List<Messages> list_mes=null;
private Context context;

public ArticleAdapter(Context context,List<Messages> list_mes) {
// TODO Auto-generated constructor stub
this.list_mes=list_mes;
this.context=context;
}


@Override
public int getCount() {
// TODO Auto-generated method stub
return list_mes.size();
}


@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list_mes.get(position);
}


@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ListItem listitem;
if(convertView==null)
{
convertView=(LinearLayout)LayoutInflater.from(context).inflate(R.layout.list_layout, null);

listitem=new ListItem();
listitem.img=(ImageView)convertView.findViewById(R.id.head_img);
listitem.name=(TextView)convertView.findViewById(R.id.name);
listitem.time=(TextView)convertView.findViewById(R.id.time);
listitem.rq=(TextView)convertView.findViewById(R.id.rq);
listitem.article=(TextView)convertView.findViewById(R.id.article);

convertView.setTag(listitem);
}else {
listitem=(ListItem)convertView.getTag();
}

listitem.img.setImageDrawable(list_mes.get(position).getImg());
listitem.name.setText(list_mes.get(position).getName());
listitem.time.setText(list_mes.get(position).getTime());
listitem.rq.setText(list_mes.get(position).getRq());
listitem.article.setText(list_mes.get(position).getArticel());
return convertView;
}

public class ListItem{
ImageView img;
TextView name;
TextView time;
TextView rq;
TextView article;
}
}
4.创建Messages,私有化图片、时间、姓名、文字、日期,添加get、set方法
public class Messages {
private Drawable img;//图片
private String name;//姓名
private String time;//时间
private String rq;//riqi
private String articel;//文字

public Drawable getImg() {
return img;
}
public void setImg(Drawable img) {
this.img = img;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getRq() {
return rq;
}
public void setRq(String rq) {
this.rq = rq;
}
public String getArticel() {
return articel;
}
public void setArticel(String articel) {
this.articel = articel;
}



}



 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一个简单的Python代码示例,用于模拟登陆新浪微博。请注意,这只是一个示例,具体的实现方法可能因为新浪微博的更新而有所不同。 ```python import requests from lxml import etree # 定义登录函数 def login(username, password): # 创建一个Session对象,用于保持登录状态 session = requests.Session() # 访问登录页面,获取一些必要的参数 url = 'https://login.sina.com.cn/signup/signin.php' response = session.get(url) html = etree.HTML(response.text) vk = html.xpath('//input[@name="vk"]/@value')[0] action = html.xpath('//form[@id="SinaLoginform"]/@action')[0] # 构造登录请求 data = { 'username': username, 'password': password, 'vk': vk, 'returntype': 'META', 'encoding': 'UTF-8', 'entry': 'sso', 'gateway': '1', 'from': 'null', 'savestate': '30', 'userticket': '0', 'pagerefer': '', 'wsseretry': 'servertime_error', 'pcid': '', 'door': '', 'appkey': '1', 's': '1', 'vsnf': '1', 'su': '', 'service': 'sso', 'servertime': '', 'nonce': '', 'pwencode': 'rsa2', 'rsakv': '', 'sp': '', 'sr': '', } response = session.post(action, data=data, allow_redirects=False) # 获取重定向链接,访问该链接即可完成登录 location = response.headers.get('Location') session.get(location) return session # 使用示例 if __name__ == '__main__': username = 'your_username' password = 'your_password' session = login(username, password) # 使用session对象访问需要登录后才能访问的页面 response = session.get('https://weibo.com/') print(response.text) ``` 请将 `your_username` 和 `your_password` 替换为您自己的用户名和密码。此外,需要安装 `requests` 和 `lxml` 两个库,可以使用 `pip` 命令进行安装。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值