京东分类
导依赖
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' implementation 'io.reactivex.rxjava2:rxjava:2.1.12' implementation 'com.jakewharton:butterknife:8.8.1' implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1' implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0' implementation 'com.squareup.retrofit2:retrofit:2.4.0' compile 'com.squareup.retrofit2:converter-gson:2.4.0' compile 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' implementation 'com.github.bumptech.glide:glide:4.7.1' annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1' implementation 'org.greenrobot:greendao:3.2.2' compile 'org.greenrobot:eventbus:3.1.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' implementation 'com.android.support:recyclerview-v7:27.+'
布局----主布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:layout_width="match_parent" android:orientation="horizontal" android:layout_height="match_parent" tools:context="com.example.com.jingdongfenlei.MainActivity"> <fragment android:name="com.example.com.jingdongfenlei.view.LeftFragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:id="@+id/fr_left"/> <fragment android:layout_width="0dp" android:layout_weight="8" android:layout_height="match_parent" android:id="@+id/right" android:name="com.example.com.jingdongfenlei.view.RightFragment" /> </LinearLayout>left—fragment
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/rec_left"> </android.support.v7.widget.RecyclerView> </LinearLayout>right—fragment
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/rec_right"> </android.support.v7.widget.RecyclerView> </LinearLayout> left——item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv_title"/> <ImageView android:layout_width="80dp" android:layout_height="80dp" android:id="@+id/img"/> </LinearLayout>right——item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tv_des"/> <com.example.com.jingdongfenlei.myview.MyGridView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/gridview" android:numColumns="3"> </com.example.com.jingdongfenlei.myview.MyGridView> </LinearLayout>gride——item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/grid_img"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/grid_tv"/> </LinearLayout>view包下LDataView
package com.example.com.jingdongfenlei.view; /** * Created by linmeihui on 2018/4/20. */ public interface LDataView { void getMessage(Object o); }LeftFragment
package com.example.com.jingdongfenlei.view; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.com.jingdongfenlei.R; import com.example.com.jingdongfenlei.adapter.LMyAdapter; import com.example.com.jingdongfenlei.bean.LeftCategory; import com.example.com.jingdongfenlei.bean.MessageBean; import com.example.com.jingdongfenlei.presenter.LDataPresenter; import com.example.com.jingdongfenlei.presenter.LMyDataPresenter; import org.greenrobot.eventbus.EventBus; import java.util.ArrayList; import java.util.List; /** * Created by linmeihui on 2018/4/20. */ public class LeftFragment extends Fragment implements LDataView,LMyAdapter.SetClick { private LMyAdapter lMyAdapter; private RecyclerView rec_left; private LMyDataPresenter lMyDataPresenter; private List<LeftCategory> data; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v=inflater.inflate(R.layout.left_fragment,null); rec_left = v.findViewById(R.id.rec_left); rec_left.setLayoutManager(new LinearLayoutManager(getActivity())); lMyDataPresenter = new LMyDataPresenter(this); //getMessage(data); lMyDataPresenter.toDataMsg(); return v; } @Override public void getMessage(Object o) { MessageBean<List<LeftCategory>> messageBean= (MessageBean<List<LeftCategory>>) o; data = messageBean.getData(); lMyAdapter = new LMyAdapter(data, getActivity()); lMyAdapter.getinstance(LeftFragment.this); rec_left.setAdapter(lMyAdapter); } @Override public void setClick(int i) { Long cid = data.get(i).getCid(); EventBus.getDefault().post(cid); } }
RDataView
package com.example.com.jingdongfenlei.view; /** * Created by linmeihui on 2018/4/20. */ public interface RDataView { void getRightMsg(Object o); }RightFragment
package com.example.com.jingdongfenlei.view; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.com.jingdongfenlei.R; import com.example.com.jingdongfenlei.adapter.LMyAdapter; import com.example.com.jingdongfenlei.adapter.RMyAdapter; import com.example.com.jingdongfenlei.bean.RightCategory; import com.example.com.jingdongfenlei.bean.RightMessage; import com.example.com.jingdongfenlei.presenter.RMyDataPresenter; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.util.List; /** * Created by linmeihui on 2018/4/20. */ public class RightFragment extends Fragment implements RDataView{ private RecyclerView rec_right; private List<RightMessage> data; private RMyDataPresenter rMyDataPresenter; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { EventBus.getDefault().register(this); View v=inflater.inflate(R.layout.right_fragment,null); rec_right = v.findViewById(R.id.rec_right); rec_right.setLayoutManager(new LinearLayoutManager(getActivity())); rMyDataPresenter = new RMyDataPresenter(this); rMyDataPresenter.getDataRight(1L); return v; } @Override public void getRightMsg(Object o) { RightCategory<List<RightMessage>> list= (RightCategory<List<RightMessage>>) o; Log.d("--", "getRightMsg: "+list.getData().size()); data = list.getData(); RMyAdapter rMyAdapter = new RMyAdapter(data, getActivity()); rec_right.setAdapter(rMyAdapter); } @Subscribe(threadMode = ThreadMode.MAIN) public void getCid(Long cid){ Log.d("--", "getCid: "+cid); rMyDataPresenter.getDataRight(cid); } @Override public void onDestroyView() { super.onDestroyView(); EventBus.getDefault().unregister(this); } }左侧API---
package com.example.com.jingdongfenlei.api; import com.example.com.jingdongfenlei.bean.LeftCategory; import com.example.com.jingdongfenlei.bean.MessageBean; import java.util.List; import io.reactivex.Flowable; import io.reactivex.Observable; import io.reactivex.internal.operators.flowable.FlowableOnBackpressureLatest; import retrofit2.http.GET; /** * Created by linmeihui on 2018/4/20. */ public interface ApiService { @GET("product/getCatagory") Observable<MessageBean<List<LeftCategory>>> getLeftMessage(); }右侧API
package com.example.com.jingdongfenlei.api; import com.example.com.jingdongfenlei.bean.RightCategory; import com.example.com.jingdongfenlei.bean.RightMessage; import java.util.Collection; import java.util.List; import io.reactivex.Flowable; import retrofit2.http.GET; import retrofit2.http.Query; /** * Created by linmeihui on 2018/4/20. */ public interface RApiService { @GET("product/getProductCatagory") Flowable<RightCategory<List<RightMessage>>>getRightMessage(@Query("cid") Long cid); }左侧数据
package com.example.com.jingdongfenlei.bean; /** * Created by linmeihui on 2018/4/20. */ public class LeftCategory { private Long cid; private String createTime; private String icon; private int isHome; private String name; public LeftCategory(Long cid, String createTime, String icon, int isHome, String name) { this.cid = cid; this.createTime = createTime; this.icon = icon; this.isHome = isHome; this.name = name; } public Long getCid() { return cid; } public void setCid(Long cid) { this.cid = cid; } public String getCreateTime() { return createTime; } public void setCreateTime(String createTime) { this.createTime = createTime; } public String getIcon() { return icon; } public void setIcon(String icon) { this.icon = icon; } public int getIsHome() { return isHome; } public void setIsHome(int isHome) { this.isHome = isHome; } public String getName() { return name; } public void setName(String name) { this.name = name; } }左侧messagebean
package com.example.com.jingdongfenlei.bean; /** * Created by linmeihui on 2018/4/20. */ public class MessageBean<T> { private String msg; private String code; private T data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public T getData() { return data; } public void setData(T data) { this.data = data; } }右侧数据
package com.example.com.jingdongfenlei.bean; /** * Created by linmeihui on 2018/4/20. */ public class RightCategory <T>{ private String msg; private String code; private T data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public T getData() { return data; } public void setData(T data) { this.data = data; } }右侧message
package com.example.com.jingdongfenlei.bean; import java.util.Collection; import java.util.List; /** * Created by linmeihui on 2018/4/20. */ public class RightMessage { /** * cid : 1 * list : [{"icon":"http://120.27.23.105/images/icon.png","name":"月饼","pcid":1,"pscid":1},{"icon":"http://120.27.23.105/images/icon.png","name":"坚果炒货","pcid":1,"pscid":2},{"icon":"http://120.27.23.105/images/icon.png","name":"糖巧","pcid":1,"pscid":3},{"icon":"http://120.27.23.105/images/icon.png","name":"休闲零食","pcid":1,"pscid":4},{"icon":"http://120.27.23.105/images/icon.png","name":"肉干肉脯","pcid":1,"pscid":5},{"icon":"http://120.27.23.105/images/icon.png","name":"饼干蛋糕","pcid":1,"pscid":6},{"icon":"http://120.27.23.105/images/icon.png","name":"蜜饯果干","pcid":1,"pscid":7},{"icon":"http://120.27.23.105/images/icon.png","name":"无糖食品","pcid":1,"pscid":8}] * name : 休闲零食 * pcid : 1 */ private String cid; private String name; private String pcid; private List<ListBean> list; public String getCid() { return cid; } public void setCid(String cid) { this.cid = cid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPcid() { return pcid; } public void setPcid(String pcid) { this.pcid = pcid; } public List<ListBean> getList() { return list; } public void setList(List<ListBean> list) { this.list = list; } }右侧list
package com.example.com.jingdongfenlei.bean; /** * Created by linmeihui on 2018/4/21. */ public class ListBean { /** * icon : http://120.27.23.105/images/icon.png * name : 月饼 * pcid : 1 * pscid : 1 */ private String icon; private String name; private int pcid; private int pscid; public String getIcon() { return icon; } public void setIcon(String icon) { this.icon = icon; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPcid() { return pcid; } public void setPcid(int pcid) { this.pcid = pcid; } public int getPscid() { return pscid; } public void setPscid(int pscid) { this.pscid = pscid; } }model层 左侧
package com.example.com.jingdongfenlei.model; import com.example.com.jingdongfenlei.presenter.LDataPresenter; /** * Created by linmeihui on 2018/4/20. */ public interface LDataModel { //请求数据方法 void toData(LDataPresenter lDataPresenter); }实现类
package com.example.com.jingdongfenlei.model; import com.example.com.jingdongfenlei.api.ApiService; import com.example.com.jingdongfenlei.bean.LeftCategory; import com.example.com.jingdongfenlei.bean.MessageBean; import com.example.com.jingdongfenlei.presenter.LDataPresenter; import java.util.List; import io.reactivex.Observer; import io.reactivex.Scheduler; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; /** * Created by linmeihui on 2018/4/20. */ public class LMyDataModel implements LDataModel { private Retrofit retrofit; private String BASE_URL = "https://www.zhaoapi.cn/"; @Override public void toData(final LDataPresenter lDataPresenter) { //日志拦截器 HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .build(); //请求数据 retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .client(client) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); //获得api ApiService apiService = retrofit.create(ApiService.class); apiService.getLeftMessage() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<MessageBean<List<LeftCategory>>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(MessageBean<List<LeftCategory>> listMessageBean) { lDataPresenter.onSuccess(listMessageBean); } @Override public void onError(Throwable e) { lDataPresenter.onFailed(); } @Override public void onComplete() { } }); } }右侧
package com.example.com.jingdongfenlei.model; import com.example.com.jingdongfenlei.presenter.RDataPresenter; /** * Created by linmeihui on 2018/4/20. */ public interface RDataModel { //请求数据 void toData(RDataPresenter rDataPresenter,Long cid); }实现类
package com.example.com.jingdongfenlei.model; import android.util.Log; import com.example.com.jingdongfenlei.api.RApiService; import com.example.com.jingdongfenlei.bean.RightCategory; import com.example.com.jingdongfenlei.bean.RightMessage; import com.example.com.jingdongfenlei.presenter.RDataPresenter; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import java.util.Collection; import java.util.List; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.DefaultSubscriber; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; /** * Created by linmeihui on 2018/4/20. */ public class RMyDataModel implements RDataModel { private String BASE_URL = "https://www.zhaoapi.cn/"; @Override public void toData(final RDataPresenter rDataPresenter,Long cid) { //日志拦截器 HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .build(); Retrofit retrofit = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl(BASE_URL) .client(client) .build(); RApiService rApiService = retrofit.create(RApiService.class); rApiService.getRightMessage(cid) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new DefaultSubscriber<RightCategory<List<RightMessage>>>() { @Override public void onNext(RightCategory<List<RightMessage>> listRightCategory) { rDataPresenter.onSuccess(listRightCategory); } @Override public void onError(Throwable t) { } @Override public void onComplete() { } }); } }presenter层
左侧
package com.example.com.jingdongfenlei.presenter; /** * Created by linmeihui on 2018/4/20. */ public interface LDataPresenter { void onSuccess(Object o); void onFailed(); }实现类
package com.example.com.jingdongfenlei.presenter; import com.example.com.jingdongfenlei.model.LDataModel; import com.example.com.jingdongfenlei.model.LMyDataModel; import com.example.com.jingdongfenlei.view.LDataView; /** * Created by linmeihui on 2018/4/20. */ public class LMyDataPresenter implements LDataPresenter { private final LDataView lDataView; private LMyDataModel lDataModel; public LMyDataPresenter (LDataView lDataView){ this.lDataView=lDataView; lDataModel=new LMyDataModel(); } @Override public void onSuccess(Object o) { lDataView.getMessage(o); } @Override public void onFailed() { } public void toDataMsg(){ lDataModel.toData(this); } }右侧
package com.example.com.jingdongfenlei.presenter; /** * Created by linmeihui on 2018/4/20. */ public interface RDataPresenter { void onSuccess(Object o); void onFailed(); }实现类
package com.example.com.jingdongfenlei.presenter; import com.example.com.jingdongfenlei.model.RDataModel; import com.example.com.jingdongfenlei.model.RMyDataModel; import com.example.com.jingdongfenlei.view.RDataView; /** * Created by linmeihui on 2018/4/20. */ public class RMyDataPresenter implements RDataPresenter{ RDataView rDataView; private final RMyDataModel rMyDataModel; public RMyDataPresenter(RDataView rDataView){ this.rDataView=rDataView; rMyDataModel = new RMyDataModel(); } @Override public void onSuccess(Object o) { rDataView.getRightMsg(o); } @Override public void onFailed() { } public void getDataRight(Long cid){ rMyDataModel.toData(this,cid); } }adapter包下
左侧
package com.example.com.jingdongfenlei.adapter; import android.content.Context; import android.support.annotation.NonNull; import android.support.v4.app.FragmentActivity; import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.example.com.jingdongfenlei.R; import com.example.com.jingdongfenlei.bean.LeftCategory; import java.util.List; /** * Created by linmeihui on 2018/4/20. */ public class LMyAdapter extends RecyclerView.Adapter{ List<LeftCategory> list; Context context; SetClick setClick; public LMyAdapter(List<LeftCategory> list, Context context) { this.context=context; this.list=list; } public void getinstance(SetClick setClick){ this.setClick=setClick; } @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view=View.inflate(context,R.layout.left_item,null); ViewHolder viewHolder=new ViewHolder(view); return viewHolder; } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) { ViewHolder viewHolder= (ViewHolder) holder; Glide.with(context).load(list.get(position).getIcon()).into(viewHolder.img); viewHolder.tv_title.setText(list.get(position).getName()); viewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setClick.setClick(position); } }); } @Override public int getItemCount() { return list.size(); } class ViewHolder extends RecyclerView.ViewHolder{ private final TextView tv_title; private final ImageView img; public ViewHolder(View itemView) { super(itemView); tv_title = itemView.findViewById(R.id.tv_title); img = itemView.findViewById(R.id.img); } } public interface SetClick{ void setClick(int i); } }右侧
package com.example.com.jingdongfenlei.adapter; import android.content.Context; import android.support.annotation.NonNull; import android.support.v4.app.FragmentActivity; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.example.com.jingdongfenlei.R; import com.example.com.jingdongfenlei.bean.ListBean; import com.example.com.jingdongfenlei.bean.RightMessage; import java.util.List; /** * Created by linmeihui on 2018/4/21. */ public class RMyAdapter extends RecyclerView.Adapter{ List<RightMessage> data; Context context; public RMyAdapter(List<RightMessage> data, Context context) { this.context=context; this.data=data; } @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { //View view=View.inflate(context,R.layout.right_item,null); View view = LayoutInflater.from(context).inflate(R.layout.right_item, parent, false); ViewHolder viewHolder=new ViewHolder(view); return viewHolder; } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { ViewHolder holder1= (ViewHolder) holder; holder1.tv_des.setText(data.get(position).getName()); GridAdapter gridAdapter = new GridAdapter(data.get(position).getList(), context); holder1.gridview.setAdapter(gridAdapter); } @Override public int getItemCount() { return data.size(); } class ViewHolder extends RecyclerView.ViewHolder{ private final GridView gridview; private final TextView tv_des; public ViewHolder(View itemView) { super(itemView); tv_des = itemView.findViewById(R.id.tv_des); gridview = itemView.findViewById(R.id.gridview); } } private class GridAdapter extends BaseAdapter{ List<ListBean> list; Context context; public GridAdapter(List<ListBean> list, Context context) { this.context=context; this.list=list; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View view, ViewGroup parent) { GridHolder holder; if (view==null) { view = View.inflate(context, R.layout.gride_item, null); holder=new GridHolder(); holder.grid_img=view.findViewById(R.id.grid_img); holder.grid_tv=view.findViewById(R.id.grid_tv); view.setTag(holder); }else { holder= (GridHolder) view.getTag(); } holder.grid_tv.setText(list.get(position).getName()); Glide.with(context).load(list.get(position).getIcon()).into(holder.grid_img); return view; } class GridHolder{ TextView grid_tv; ImageView grid_img; } } }自定义gridview
package com.example.com.jingdongfenlei.myview; import android.content.Context; import android.util.AttributeSet; import android.widget.GridView; /** * Created by linmeihui on 2018/4/21. */ public class MyGridView extends GridView { public MyGridView(Context context) { super(context); } public MyGridView(Context context, AttributeSet attrs) { super(context, attrs); } public MyGridView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int i = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, i); } }