Android achieves the same layout as WeChat chat

Source: Internet
Author: User
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    >    <TextView android:id="@+id/text"    android:paddingTop="10dip"    android:textColor="#FFA07A"    android:background="@drawable/bg_normal"    android:layout_width="wrap_content"    android:layout_height="wrap_content"/></LinearLayout>

The layout file is as follows:

One is the main program layout:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:paddingTop="10dip"    android:paddingLeft="30dip"    android:paddingRight="30dip"    >    <ListView android:id="@+id/listview"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:clickable="false"    android:scrollbars="none">    </ListView></LinearLayout>

The other is the layout of the subview of listview.

The main program code is as follows:

package com.cloay;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ListView;import android.widget.TextView;/** *  * MyListTestActivity.java * @author cloay * 2011-10-18 */public class TestActivity extends Activity {    /** Called when the activity is first created. */private ListView listView = null;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        initView();    }private void initView() {listView = (ListView)findViewById(R.id.listview);        listView.setDividerHeight(0);        ListAdapter adapter = new ListAdapter(this, 5);        listView.setAdapter(adapter);}        public class ListAdapter extends BaseAdapter {    private LayoutInflater inflater;    private int size;    public ListAdapter(Context context, int size){    this.size = size;    inflater = LayoutInflater.from(context);    }@Overridepublic int getCount() {// TODO Auto-generated method stubreturn size;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn null;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn 0;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubconvertView = inflater.inflate(R.layout.list, null);TextView text = (TextView) convertView.findViewById(R.id.text);text.setText(position + ":This is a test !dasgagaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaafdfffffdffg");convertView.setEnabled(false);return convertView;}    }}

The running interface is as follows:

Note: Please indicate the source for reprinting.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.