码迷,mamicode.com
首页 > 移动开发 > 详细

安卓布局

时间:2018-12-18 17:20:20      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:upd   edittext   方法   .class   activity   scree   selector   [1]   main   

1、activity

技术分享图片

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
                                              android:id="@+id/mainLinearLayout"
                                              style="@style/Layout.Wrap">

    <android.support.v4.view.ViewPager
            android:id="@+id/mainViewPager"
            style="@style/Layout.Main"
            android:layout_weight="1" />

    <View
            style="@style/View.Line"
            android:background="@color/whiteAdd" />

    <android.support.v7.widget.LinearLayoutCompat
            android:id="@+id/navigationLinearLayout"
            style="@style/Layout.Horizontal"
            android:layout_height="48dip">

        <android.support.v7.widget.AppCompatTextView
                android:id="@+id/homeTextView"
                style="@style/TextView.Navigation"
                android:drawableTop="@drawable/ic_navigation_home"
                android:text="@string/home" />

        <android.support.v7.widget.AppCompatTextView
                android:id="@+id/cateTextView"
                style="@style/TextView.Navigation"
                android:drawableTop="@drawable/ic_navigation_cate"
                android:text="@string/classification" />

        <android.support.v7.widget.AppCompatTextView
                android:id="@+id/searchTextView"
                style="@style/TextView.Navigation"
                android:drawableTop="@drawable/ic_navigation_search"
                android:text="@string/search" />

        <android.support.v7.widget.AppCompatTextView
                android:id="@+id/cartTextView"
                style="@style/TextView.Navigation"
                android:drawableTop="@drawable/ic_navigation_cart"
                android:text="@string/cart" />

        <android.support.v7.widget.AppCompatTextView
                android:id="@+id/mineTextView"
                style="@style/TextView.Navigation"
                android:drawableTop="@drawable/ic_navigation_mine"
                android:text="@string/mine" />

    </android.support.v7.widget.LinearLayoutCompat>

</android.support.v7.widget.LinearLayoutCompat>

  cs 代码:

 List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(new HomeFragment());
        fragmentList.add(new CateFragment());
        fragmentList.add(new SearchFragment());
        fragmentList.add(new CartFragment());
        fragmentList.add(new MineFragment());
@Override
    public void initData() {

        exitTimeLong = 0L;

        navigationNormalDrawable = new Drawable[navigationTextView.length];
        navigationNormalDrawable[0] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_home);
        navigationNormalDrawable[1] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_cate);
        navigationNormalDrawable[2] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_search);
        navigationNormalDrawable[3] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_cart);
        navigationNormalDrawable[4] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_mine);

        navigationPressDrawable = new Drawable[navigationTextView.length];
        navigationPressDrawable[0] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_home_press);
        navigationPressDrawable[1] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_cate_press);
        navigationPressDrawable[2] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_search_press);
        navigationPressDrawable[3] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_cart_press);
        navigationPressDrawable[4] = BaseApplication.get().getMipmap(R.drawable.ic_navigation_mine_press);

        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(new HomeFragment());
        fragmentList.add(new CateFragment());
        fragmentList.add(new SearchFragment());
        fragmentList.add(new CartFragment());
        fragmentList.add(new MineFragment());

        mainViewPager.setAdapter(new BaseFragmentAdapter(getSupportFragmentManager(), fragmentList));
        mainViewPager.setOffscreenPageLimit(navigationTextView.length);

        // checkVersion();
        broadcastReceiver = null;
        updateNavigation(0);

    }

  

2、Fragment

技术分享图片

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainLinearLayout"
    style="@style/Layout.Main">

    <android.support.v7.widget.LinearLayoutCompat
        android:id="@+id/toolbarLinearLayout"
        style="@style/Layout.Horizontal"
        android:layout_height="48dip"
        android:background="@color/primary">

        <android.support.v7.widget.AppCompatImageView
            android:id="@+id/scanImageView"
            style="@style/ImageView.Toolbar"
            android:background="@drawable/selector_color_primary"
            android:src="@drawable/ic_action_scan_white" />

        <android.support.v7.widget.AppCompatEditText
            android:id="@+id/searchEditText"
            style="@style/EditText.SearchToolbar" />

        <android.support.v7.widget.AppCompatImageView
            android:id="@+id/messageImageView"
            style="@style/ImageView.Toolbar"
            android:background="@drawable/selector_color_primary"
            android:src="@drawable/ic_action_message_white" />

    </android.support.v7.widget.LinearLayoutCompat>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/mainSwipeRefreshLayout"
        style="@style/Layout.Main">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/mainScrollView"
            style="@style/Layout.Main">

            <android.support.v7.widget.LinearLayoutCompat style="@style/Layout.Main">

                <com.youth.banner.Banner
                    android:id="@+id/mainBanner"
                    style="@style/Layout.Wrap"
                    android:layout_height="200dip" />

                <android.support.v7.widget.LinearLayoutCompat
                    android:id="@+id/navigationLinearLayout"
                    style="@style/Layout.Wrap"
                    android:background="@drawable/selector_color_white">

                    <android.support.v7.widget.LinearLayoutCompat
                        style="@style/Layout.Wrap"
                        android:orientation="horizontal"
                        android:paddingBottom="8dip"
                        android:paddingTop="16dip">

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/oneLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/oneImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/oneTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/twoLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/twoImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/twoTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/thrLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/thrImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/thrTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/fouLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/fouImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/fouTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/fivLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/fivImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/fivTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                    </android.support.v7.widget.LinearLayoutCompat>

                    <android.support.v7.widget.LinearLayoutCompat
                        style="@style/Layout.Wrap"
                        android:orientation="horizontal"
                        android:paddingBottom="16dip"
                        android:paddingTop="8dip">

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/sixLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/sixImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/sixTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/sevLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/sevImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/sevTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/eigLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/eigImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/eigTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/nigLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/nigImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/nigTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                        <android.support.v7.widget.LinearLayoutCompat
                            android:id="@+id/tenLinearLayout"
                            style="@style/Layout.Wrap"
                            android:layout_weight="1">

                            <android.support.v7.widget.AppCompatImageView
                                android:id="@+id/tenImageView"
                                style="@style/ImageView.Main"
                                android:layout_width="56dip"
                                android:layout_height="56dip"
                                android:layout_gravity="center"
                                android:scaleType="center" />

                            <android.support.v7.widget.AppCompatTextView
                                android:id="@+id/tenTextView"
                                style="@style/TextView.Small"
                                android:layout_width="match_parent"
                                android:layout_marginTop="4dip"
                                android:gravity="center" />

                        </android.support.v7.widget.LinearLayoutCompat>

                    </android.support.v7.widget.LinearLayoutCompat>

                </android.support.v7.widget.LinearLayoutCompat>

                <View style="@style/View.Line" />

                <android.support.v7.widget.LinearLayoutCompat
                    style="@style/Layout.Horizontal"
                    android:layout_height="48dip"
                    android:background="@color/white"
                    android:paddingLeft="8dip"
                    android:paddingRight="8dip">

                    <android.support.v7.widget.AppCompatImageView
                        android:layout_width="wrap_content"
                        android:layout_height="48dip"
                        android:src="@mipmap/ic_home_new_notice" />

                    <View
                        style="@style/View.Horizontal"
                        android:layout_marginBottom="8dip"
                        android:layout_marginLeft="4dip"
                        android:layout_marginRight="4dip"
                        android:layout_marginTop="8dip" />

                    <android.support.v7.widget.AppCompatImageView
                        android:layout_width="wrap_content"
                        android:layout_height="48dip"
                        android:layout_marginLeft="4dip"
                        android:layout_marginRight="4dip"
                        android:src="@mipmap/ic_home_notice" />

                    <com.sunfusheng.marqueeview.MarqueeView
                        android:id="@+id/noticeMarqueeView"
                        android:layout_width="match_parent"
                        android:layout_height="32dip"
                        android:layout_gravity="center"
                        android:layout_weight="1"
                        app:mvAnimDuration="1000"
                        app:mvDirection="bottom_to_top"
                        app:mvGravity="left"
                        app:mvInterval="3000"
                        app:mvSingleLine="true"
                        app:mvTextColor="@color/greyAdd"
                        app:mvTextSize="12sp" />

                    <android.support.v7.widget.AppCompatTextView
                        android:id="@+id/noticeTextView"
                        style="@style/TextView.Small"
                        android:layout_height="48dip"
                        android:paddingLeft="4dip"
                        android:paddingRight="4dip"
                        android:text="更多..."
                        tools:ignore="HardcodedText" />

                </android.support.v7.widget.LinearLayoutCompat>

                <View style="@style/View.Line" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/mainRecyclerView"
                    style="@style/Layout.Main" />

            </android.support.v7.widget.LinearLayoutCompat>

        </android.support.v4.widget.NestedScrollView>

    </android.support.v4.widget.SwipeRefreshLayout>

</android.support.v7.widget.LinearLayoutCompat>

  cs代码:

package com.wbh.mall.activity.main;

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.*;
import android.view.View;
import com.alibaba.fastjson.JSON;
import com.loopj.android.http.TextHttpResponseHandler;
import com.sunfusheng.marqueeview.MarqueeView;
import com.wbh.base.bean.ArticleBean;
import com.wbh.base.bean.ClassBean;
import com.wbh.base.bean.HomeBean;
import com.wbh.base.bean.JsonResult;
import com.wbh.base.bean.home.AdvListBean;
import com.wbh.base.bean.home.HomeGoodsBean;
import com.wbh.base.bean.home.HomeTitleBean;
import com.wbh.base.event.MainPositionEvent;
import com.wbh.base.restful.service.HomeService;
import com.wbh.mall.activity.home.NoticeActivity;
import com.wbh.mall.adapter.HomeGoodsListAdapter;
import com.wbh.mall.adapter.HomeListAdapter;
import com.wbh.mall.base.*;
import com.wbh.mall.outlet.R;
import com.wbh.util.JsonUtil;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import cz.msebera.android.httpclient.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 主内容页
 *
 * @author wbh
 */

@ContentView(R.layout.fragment_main_home)
public class HomeFragment extends BaseFragment {

    @ViewInject(R.id.mainSwipeRefreshLayout)
    private SwipeRefreshLayout mainSwipeRefreshLayout;
    @ViewInject(R.id.searchEditText)
    private AppCompatEditText searchEditText;
    @ViewInject(R.id.messageImageView)
    private AppCompatImageView messageImageView;
    @ViewInject(R.id.scanImageView)
    private AppCompatImageView scanImageView;
    @ViewInject(R.id.mainBanner)
    private Banner mainBanner;
    @ViewInject(R.id.navigationLinearLayout)
    private LinearLayoutCompat navigationLinearLayout;
    @ViewInject(R.id.oneLinearLayout)
    private LinearLayoutCompat oneLinearLayout;
    @ViewInject(R.id.oneImageView)
    private AppCompatImageView oneImageView;
    @ViewInject(R.id.oneTextView)
    private AppCompatTextView oneTextView;
    @ViewInject(R.id.twoLinearLayout)
    private LinearLayoutCompat twoLinearLayout;
    @ViewInject(R.id.twoImageView)
    private AppCompatImageView twoImageView;
    @ViewInject(R.id.twoTextView)
    private AppCompatTextView twoTextView;
    @ViewInject(R.id.thrLinearLayout)
    private LinearLayoutCompat thrLinearLayout;
    @ViewInject(R.id.thrImageView)
    private AppCompatImageView thrImageView;
    @ViewInject(R.id.thrTextView)
    private AppCompatTextView thrTextView;
    @ViewInject(R.id.fouLinearLayout)
    private LinearLayoutCompat fouLinearLayout;
    @ViewInject(R.id.fouImageView)
    private AppCompatImageView fouImageView;
    @ViewInject(R.id.fouTextView)
    private AppCompatTextView fouTextView;
    @ViewInject(R.id.fivLinearLayout)
    private LinearLayoutCompat fivLinearLayout;
    @ViewInject(R.id.fivImageView)
    private AppCompatImageView fivImageView;
    @ViewInject(R.id.fivTextView)
    private AppCompatTextView fivTextView;
    @ViewInject(R.id.sixLinearLayout)
    private LinearLayoutCompat sixLinearLayout;
    @ViewInject(R.id.sixImageView)
    private AppCompatImageView sixImageView;
    @ViewInject(R.id.sixTextView)
    private AppCompatTextView sixTextView;
    @ViewInject(R.id.sevLinearLayout)
    private LinearLayoutCompat sevLinearLayout;
    @ViewInject(R.id.sevImageView)
    private AppCompatImageView sevImageView;
    @ViewInject(R.id.sevTextView)
    private AppCompatTextView sevTextView;
    @ViewInject(R.id.eigLinearLayout)
    private LinearLayoutCompat eigLinearLayout;
    @ViewInject(R.id.eigImageView)
    private AppCompatImageView eigImageView;
    @ViewInject(R.id.eigTextView)
    private AppCompatTextView eigTextView;
    @ViewInject(R.id.nigLinearLayout)
    private LinearLayoutCompat nigLinearLayout;
    @ViewInject(R.id.nigImageView)
    private AppCompatImageView nigImageView;
    @ViewInject(R.id.nigTextView)
    private AppCompatTextView nigTextView;
    @ViewInject(R.id.tenLinearLayout)
    private LinearLayoutCompat tenLinearLayout;
    @ViewInject(R.id.tenImageView)
    private AppCompatImageView tenImageView;
    @ViewInject(R.id.tenTextView)
    private AppCompatTextView tenTextView;
    @ViewInject(R.id.noticeMarqueeView)
    private MarqueeView noticeMarqueeView;
    @ViewInject(R.id.noticeTextView)
    private AppCompatTextView noticeTextView;
    @ViewInject(R.id.mainRecyclerView)
    private RecyclerView mainRecyclerView;

    private HomeListAdapter mainAdapter;
    private ArrayList<HomeBean> mainArrayList;
    private List<ArticleBean> articleArrayList;
    private HomeService homeService;
    private Context ct;

    @Override
    public void initData() {
        ct = getActivity();
        articleArrayList = new ArrayList<>();
        mainBanner.setImageLoader(new UBLImageLoader());
        mainBanner.setDelayTime(BaseConstant.TIME_DELAY);
        mainBanner.setIndicatorGravity(BannerConfig.CENTER);
        mainBanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);

        mainArrayList = new ArrayList<>();
        mainAdapter = new HomeListAdapter(getActivity(), mainArrayList);
        BaseApplication.get().setRecyclerView(getActivity(), mainRecyclerView, mainAdapter);
        BaseApplication.get().setSwipeRefreshLayout(mainSwipeRefreshLayout);

        getIndex();
        getGG();

    }

    @Override
    public void initEven() {

        //  scanImageView.setOnClickListener(view -> BaseApplication.get().start(getActivity(), CaptureActivity.class, BaseConstant.CODE_QRCODE));

        searchEditText.setOnClickListener(view -> BaseBusClient.get().post(new MainPositionEvent(2)));

        //   messageImageView.setOnClickListener(view -> BaseApplication.get().startCheckLogin(getActivity(), ChatListActivity.class));

        mainSwipeRefreshLayout.setOnRefreshListener(() -> new Handler().postDelayed(() -> {
            mainSwipeRefreshLayout.setRefreshing(false);
            getIndex();
            getGG();
        }, BaseConstant.TIME_REFRESH));

          noticeMarqueeView.setOnItemClickListener((position, textView) ->
                  BaseApplication.get().startNoticeShow(getActivity(),
                  articleArrayList.get(position)));

          noticeTextView.setOnClickListener(view -> BaseApplication.get().start(getActivity(), NoticeActivity.class));

    }

    @Override
    public void onStart() {
        super.onStart();
        mainBanner.startAutoPlay();
        noticeMarqueeView.startFlipping();
    }

    @Override
    public void onStop() {
        super.onStop();
        mainBanner.stopAutoPlay();
        noticeMarqueeView.stopFlipping();
    }

    //自定义方法

    private void getIndex() {
        if (homeService == null) {
            homeService = new HomeService(ct);
        }
        String loginkey = BaseShared.get().getString(BaseConstant.SHARED_KEY);
        homeService.getIndex(loginkey, new TextHttpResponseHandler() {

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                BaseToast.show(responseString);
                new BaseCountTime(BaseConstant.TIME_COUNT, BaseConstant.TIME_TICK) {
                    @Override
                    public void onFinish() {
                        super.onFinish();
                        getIndex();
                    }
                }.start();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                JsonResult jsonResult = JSON.parseObject(responseString, JsonResult.class);
                if (jsonResult.getErrorCode() == 1) {
                    BaseToast.show(jsonResult.getErrorMessage());
                    BaseToast.show("解析数据失败");
                } else {
                    // 绑定数据
                    try {
                        String name;
                        HomeBean indexBean;
                        JSONObject jsonObject;
                        mainArrayList.clear();
                        navigationLinearLayout.setVisibility(View.GONE);
                        com.alibaba.fastjson.JSONObject data = (com.alibaba.fastjson.JSONObject) jsonResult.getData();
                        String index = JSON.toJSONString(data);
                        indexBean = JSON.parseObject(index, HomeBean.class);
                        List<AdvListBean> showList = indexBean.getShowList();
                        if (showList.size() == 0) {
                            mainBanner.setVisibility(View.GONE);
                        } else {
                            mainBanner.setVisibility(View.VISIBLE);
                            List<String> image = new ArrayList<>();
                            final List<String> type = new ArrayList<>();
                            final List<String> dataAd = new ArrayList<>();


                            for (int i = 0; i < showList.size(); i++) {
                                image.add(showList.get(i).getImage());
                                type.add(showList.get(i).getType());
                                dataAd.add(showList.get(i).getData());
                            }

                            mainBanner.setOnBannerListener(position -> BaseApplication.get().startTypeValue(getActivity(), type.get(position), dataAd.get(position)));
                            mainBanner.update(image);
                            mainBanner.start();
                        }
                        if(indexBean.getHomeTitleBean()!=null) {
                            CreateTitle(indexBean.getHomeTitleBean());
                        }

                        mainArrayList.add(indexBean);
                        mainAdapter.notifyDataSetChanged();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });


    }


    private void getGG() {
        if (homeService == null) {
            homeService = new HomeService(ct);
        }
        String siteId = "1";
        String categoryId="4";
        homeService.gonggao(  siteId, categoryId, new TextHttpResponseHandler() {

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                articleArrayList.clear();
                JsonResult jsonResult = JSON.parseObject(responseString, JsonResult.class);
                com.alibaba.fastjson.JSONArray data = (com.alibaba.fastjson.JSONArray) jsonResult.getData();
                String dataStr = JSON.toJSONString(data);
                articleArrayList = JSON.parseArray(dataStr, ArticleBean.class);
                List<String> list = new ArrayList<>();
                for (int i = 0; i < articleArrayList.size(); i++) {
                    list.add(articleArrayList.get(i).getArticleTitle());
                }
                noticeMarqueeView.startWithList(list);
            }
        });


    }

    private void CreateTitle(HomeTitleBean homeTitleBean) {

        try {

            //第一个
            final String squareType = homeTitleBean.getSquareType();
            final String squareData = homeTitleBean.getSquareData();
            oneTextView.setText( homeTitleBean.getSquareIcoName() );
            oneImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getSquareIcoColor())));
            BaseImageLoader.get().display(homeTitleBean.getSquareImage(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), oneImageView);
            oneLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), squareType, squareData));
            //第二个
            final String rectangle1Type =homeTitleBean.getRectangle1Type();
            final String rectangle1Data =homeTitleBean.getRectangle1Data();
            twoTextView.setText(homeTitleBean.getSquareIcoName());
            twoImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getRectangle1IcoColor() )));
            BaseImageLoader.get().display(homeTitleBean.getRectangle1Image(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), twoImageView);
            twoLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), rectangle1Type, rectangle1Data));
            //第三个
            final String rectangle2Type = homeTitleBean.getRectangle2Type();
            final String rectangle2Data = homeTitleBean.getRectangle2Data();
            thrTextView.setText(homeTitleBean.getRectangle2IcoName());
            thrImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getRectangle2IcoColor())));
            BaseImageLoader.get().display(homeTitleBean.getRectangle2Image(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), thrImageView);
            thrLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), rectangle2Type, rectangle2Data));
            //第四个
            final String rectangle3Type = homeTitleBean.getRectangle3Type();
            final String rectangle3Data = homeTitleBean.getRectangle3Data();
            fouTextView.setText(homeTitleBean.getRectangle3IcoName());
            fouImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getRectangle3IcoColor())));
            BaseImageLoader.get().display(homeTitleBean.getRectangle3Image(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), fouImageView);
            fouLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), rectangle3Type, rectangle3Data));
            //第五个
            final String rectangle4Type = homeTitleBean.getRectangle4Type();
            final String rectangle4Data = homeTitleBean.getRectangle4Data();
            fivTextView.setText(homeTitleBean.getRectangle4IcoName());
            fivImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getRectangle4IcoColor())));
            BaseImageLoader.get().display(homeTitleBean.getRectangle4Image(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), fivImageView);
            fivLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), rectangle4Type, rectangle4Data));
            //第六个
            final String rectangle5Type =  homeTitleBean.getRectangle5Type();
            final String rectangle5Data = homeTitleBean.getRectangle5Data();
            sixTextView.setText(homeTitleBean.getRectangle5IcoName());
            sixImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getRectangle5IcoColor())));
            BaseImageLoader.get().display(homeTitleBean.getRectangle5Image(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), sixImageView);
            sixLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), rectangle5Type, rectangle5Data));
            //第七个
            final String rectangle6Type = homeTitleBean.getRectangle6Type();
            final String rectangle6Data = homeTitleBean.getRectangle6Data();
            sevTextView.setText(homeTitleBean.getRectangle6IcoName());
            sevImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getRectangle6IcoColor())));
            BaseImageLoader.get().display(homeTitleBean.getRectangle6Image(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), sevImageView);
            sevLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), rectangle6Type, rectangle6Data));
            //第八个
            final String rectangle7Type = homeTitleBean.getRectangle7Type();
            final String rectangle7Data = homeTitleBean.getRectangle7Data();
            eigTextView.setText(homeTitleBean.getRectangle7IcoName());
            eigImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getRectangle7IcoColor())));
            BaseImageLoader.get().display(homeTitleBean.getRectangle7Image(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), eigImageView);
            eigLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), rectangle7Type, rectangle7Data));
            //第九个
            final String rectangle8Type = homeTitleBean.getRectangle8Type();
            final String rectangle8Data = homeTitleBean.getRectangle8Data();
            nigTextView.setText(homeTitleBean.getRectangle8IcoName());
            nigImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getRectangle8IcoColor())));
            BaseImageLoader.get().display(homeTitleBean.getRectangle8Image(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), nigImageView);
            nigLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), rectangle8Type, rectangle8Data));
            //第十个
            final String rectangle9Type = homeTitleBean.getRectangle9Type();
            final String rectangle9Data = homeTitleBean.getRectangle9Data();
            tenTextView.setText(homeTitleBean.getRectangle9IcoName());
            tenImageView.setBackgroundDrawable(BaseApplication.get().getGradientDrawable(BaseApplication.get().dipToPx(28), Color.parseColor(homeTitleBean.getRectangle9IcoColor())));
            BaseImageLoader.get().display(homeTitleBean.getRectangle9Image(), BaseApplication.get().dipToPx(28), BaseApplication.get().dipToPx(28), tenImageView);
            tenLinearLayout.setOnClickListener(view -> BaseApplication.get().startTypeValue(getActivity(), rectangle9Type, rectangle9Data));
            navigationLinearLayout.setVisibility(View.VISIBLE);
        } catch (Exception e) {
            navigationLinearLayout.setVisibility(View.GONE);
            e.printStackTrace();
        }
    }
}

  3、Layout

这就是控件级别的了,层div;

 

安卓布局

标签:upd   edittext   方法   .class   activity   scree   selector   [1]   main   

原文地址:https://www.cnblogs.com/hoge66/p/10137913.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!