zoukankan      html  css  js  c++  java
  • 安卓购物商城

     
    <?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:orientation="vertical"
        >
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:text="购物商城"
            android:textSize="18sp"
            android:textColor="#ffffff"
            android:background="#ff8f03"
            android:gravity="center"
            />
    
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/lv"
            />
    
    </LinearLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="16dp"
        >
        <ImageView
            android:layout_width="120dp"
            android:layout_height="90dp"
            android:layout_centerVertical="true"
            android:id="@+id/iv"
            />
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/iv"
            android:layout_centerVertical="true"
            >
            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="桌子"
                android:textSize="20sp"
                android:textColor="#000000"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tv_price"
                android:text="价格:"
                android:textSize="20sp"
                android:layout_marginTop="10dp"
                android:layout_below="@+id/title"
                android:textColor="#ff8f03"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/price"
                android:text="1000"
                android:textSize="20sp"
                android:layout_below="@+id/title"
                android:layout_toRightOf="@+id/tv_price"
                android:textColor="#ff8f03"
                android:layout_marginTop="10dp"
                />
    
    
        </RelativeLayout>
    
    </RelativeLayout>
    package com.example.myapplication;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.ImageView;
    import android.widget.ListView;
    import android.widget.TextView;
    
    public class MainActivity extends AppCompatActivity {
        private String[] titles ={"草莓","荔枝","火龙果","橙子","芒果","樱桃"};
        private String[] prices ={"15元/kg","10元/kg","30元/kg","5元/kg","20元/kg","40元/kg"};
        private  int[] icons ={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e,R.drawable.f};
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            ListView listView=  findViewById(R.id.lv);
            MyBaseAdapter adapter =new MyBaseAdapter();
            listView.setAdapter(adapter);
        }
    
        class MyBaseAdapter extends BaseAdapter{
    
            @Override
            public int getCount() {
                return titles.length;
            }
    
            @Override
            public Object getItem(int position) {
                return titles[position];
            }
    
            @Override
            public long getItemId(int position) {
                return position;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                ViewHolder holder;
                if(convertView==null){
                    convertView= View.inflate(MainActivity.this,R.layout.list_item,null);
                    holder =new ViewHolder();
                    holder.title = convertView.findViewById(R.id.title);
                    holder.price = convertView.findViewById(R.id.price);
                    holder.iv= convertView.findViewById(R.id.iv);
                    convertView.setTag(holder);
                }else {
                    holder=(ViewHolder) convertView.getTag();
                }
                holder.title.setText(titles[position]);
                holder.price.setText(prices[position]);
                holder.iv.setImageResource(icons[position]);
                return convertView;
            }
        }
        class ViewHolder{
            TextView title;
            TextView price;
            ImageView iv;
        }
    }
  • 相关阅读:
    "饼状图/环形图/玫瑰图"组件:<chart-pie> —— 快应用组件库H-UI
    "柱状图"组件:<chart-bar> —— 快应用组件库H-UI
    "折线图"组件:<chart-line> —— 快应用组件库H-UI
    "进度条"组件:<chart-progress> —— 快应用组件库H-UI
    "警告提示"组件:<alert> —— 快应用组件库H-UI
    "全局提示"组件:<message> —— 快应用组件库H-UI
    "滑动操作"组件:<swipe-action> —— 快应用组件库H-UI
    Git使用总结之修改了用户名之后git无法使用
    Facebook授权登录
    Android键盘显示和隐藏
  • 原文地址:https://www.cnblogs.com/FALEDA/p/13878919.html
Copyright © 2011-2022 走看看