欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)現(xiàn)京東App分類頁面效果

 更新時間:2018年02月11日 11:05:53   作者:隔壁小王66  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)京東App分類頁面效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

今天群里有人問了關(guān)于仿京東App分類頁面的實(shí)現(xiàn),而我之前正好查過這方面的資料,手上正好有一個demo,正好分享給大家看看,個人覺得效果棒棒噠!

首先來看效果圖吧

是不是很6呢,來分析這個demo的主體構(gòu)成吧,頂部為搜索欄,左側(cè)是scroview,不要擔(dān)心優(yōu)化問題,因?yàn)閟croview里面的TextView是動態(tài)生成的,完全不用擔(dān)心優(yōu)化問題,右側(cè)是viewPager,Scroview可以控制viewPager的滑動,反之ViewPager也可以控制scroview的滑動。

閑話少說,直接上代碼:

activity_main

<?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" >

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="52dp"
    android:background="@color/activity_graybg"
    android:baselineAligned="false"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="horizontal"
    android:paddingBottom="8dp"
    android:paddingLeft="10dp"
    android:paddingRight="15dp"
    android:paddingTop="8dp" >

    <RelativeLayout
      android:id="@+id/search_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      >

      <EditText
        android:id="@+id/search_edit"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="3dp"
        android:layout_marginRight="5dp"
        android:layout_toLeftOf="@+id/search_line"
        android:background="@drawable/transparent_edittext_bg"
        android:hint="@string/search_hint"
        android:paddingLeft="@dimen/space_8"
        android:maxLength="50"
        android:singleLine="true"
        android:textColor="@color/black_text_color"
        android:textColorHint="@color/gray_text_color"
        android:textSize="@dimen/text_mid_size" />

      <View
        android:id="@+id/search_line"
        android:layout_width="@dimen/yipx"
        android:layout_height="match_parent"
        android:layout_toLeftOf="@+id/search_btn"
        android:background="@color/activity_graybg" />

      <ImageView
        android:id="@+id/search_btn"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:contentDescription="@null"
        android:src="@drawable/search_btn_bg" />
    </RelativeLayout>

    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="5"
      android:gravity="center_horizontal" >

      <ImageView
        android:id="@+id/type_icon"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@null"
        android:padding="4dp"
        android:layout_margin="@dimen/space_4"
        android:src="@drawable/barcode_normal"
        android:visibility="visible" />
    </LinearLayout>
  </LinearLayout>

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ScrollView
      android:id="@+id/tools_scrlllview"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="3"
      android:fadingEdge="none"
      android:scrollbars="none" >

      <LinearLayout
        android:id="@+id/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="vertical" />
    </ScrollView>

    <android.support.v4.view.ViewPager
      android:id="@+id/goods_pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="1" />
  </LinearLayout>

</LinearLayout>

上面是主頁面布局,下面放上主頁面代碼

package up72.com.testtype;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

  private String toolsList[];
  private TextView toolsTextViews[];
  private View views[];
  private LayoutInflater inflater;
  private ScrollView scrollView;
  private int scrllViewWidth = 0, scrollViewMiddle = 0;
  private ViewPager shop_pager;
  private int currentItem = 0;
  private ShopAdapter shopAdapter;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    scrollView = (ScrollView) findViewById(R.id.tools_scrlllview);
    shopAdapter = new ShopAdapter(getSupportFragmentManager());
    inflater = LayoutInflater.from(this);
    showToolsView();
    initPager();
  }

  /**
   * 動態(tài)生成顯示items中的textview
   */
  private void showToolsView() {
    toolsList = new String[]{"常用分類", "潮流女裝", "品牌男裝", "內(nèi)衣配飾", "家用電器", "手機(jī)數(shù)碼", "電腦辦公", "個護(hù)化妝", "母嬰頻道", "食物生鮮", "酒水飲料", "家居家紡", "整車車品", "鞋靴箱包", "運(yùn)動戶外", "圖書", "玩具樂器", "鐘表", "居家生活", "珠寶飾品", "音像制品", "家具建材", "計(jì)生情趣", "營養(yǎng)保健", "奢侈禮品", "生活服務(wù)", "旅游出行"};
    LinearLayout toolsLayout = (LinearLayout) findViewById(R.id.tools);
    toolsTextViews = new TextView[toolsList.length];
    views = new View[toolsList.length];

    for (int i = 0; i < toolsList.length; i++) {
      View view = inflater.inflate(R.layout.item_b_top_nav_layout, null);
      view.setId(i);
      view.setOnClickListener(toolsItemListener);
      TextView textView = (TextView) view.findViewById(R.id.text);
      textView.setText(toolsList[i]);
      toolsLayout.addView(view);
      toolsTextViews[i] = textView;
      views[i] = view;
    }
    changeTextColor(0);
  }

  private View.OnClickListener toolsItemListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      shop_pager.setCurrentItem(v.getId());
    }
  };


  /**
   * initPager<br/>
   * 初始化ViewPager控件相關(guān)內(nèi)容
   */
  private void initPager() {
    shop_pager = (ViewPager) findViewById(R.id.goods_pager);
    shop_pager.setAdapter(shopAdapter);
    shop_pager.setOnPageChangeListener(onPageChangeListener);
  }

  /**
   * OnPageChangeListener<br/>
   * 監(jiān)聽ViewPager選項(xiàng)卡變化事的事件
   */

  private ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageSelected(int arg0) {
      if (shop_pager.getCurrentItem() != arg0) shop_pager.setCurrentItem(arg0);
      if (currentItem != arg0) {
        changeTextColor(arg0);
        changeTextLocation(arg0);
      }
      currentItem = arg0;
    }

    @Override
    public void onPageScrolled(int arg0, float arg1, int arg2) {
    }

    @Override
    public void onPageScrollStateChanged(int arg0) {
    }
  };


  /**
   * ViewPager 加載選項(xiàng)卡
   *
   * @author Administrator
   */
  private class ShopAdapter extends FragmentPagerAdapter {
    public ShopAdapter(FragmentManager fm) {
      super(fm);
    }

    @Override
    public Fragment getItem(int arg0) {
      Fragment fragment = new Fragment_pro_type();
      Bundle bundle = new Bundle();
      String str = toolsList[arg0];
      bundle.putString("typename", str);
      fragment.setArguments(bundle);
      return fragment;
    }

    @Override
    public int getCount() {
      return toolsList.length;
    }
  }


  /**
   * 改變textView的顏色
   *
   * @param id
   */
  private void changeTextColor(int id) {
    for (int i = 0; i < toolsTextViews.length; i++) {
      if (i != id) {
        toolsTextViews[i].setBackgroundResource(android.R.color.transparent);
        toolsTextViews[i].setTextColor(0xff000000);
      }
    }
    toolsTextViews[id].setBackgroundResource(android.R.color.white);
    toolsTextViews[id].setTextColor(0xffff5d5e);
  }


  /**
   * 改變欄目位置
   *
   * @param clickPosition
   */
  private void changeTextLocation(int clickPosition) {

    int x = (views[clickPosition].getTop() - getScrollViewMiddle() + (getViewheight(views[clickPosition]) / 2));
    scrollView.smoothScrollTo(0, x);
  }

  /**
   * 返回scrollview的中間位置
   *
   * @return
   */
  private int getScrollViewMiddle() {
    if (scrollViewMiddle == 0)
      scrollViewMiddle = getScrollViewheight() / 2;
    return scrollViewMiddle;
  }

  /**
   * 返回ScrollView的寬度
   *
   * @return
   */
  private int getScrollViewheight() {
    if (scrllViewWidth == 0)
      scrllViewWidth = scrollView.getBottom() - scrollView.getTop();
    return scrllViewWidth;
  }

  /**
   * 返回view的寬度
   *
   * @param view
   * @return
   */
  private int getViewheight(View view) {
    return view.getBottom() - view.getTop();
  }
}

在貼上fragment代碼

package up72.com.testtype;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;


import java.util.ArrayList;


public class Fragment_pro_type extends Fragment {
  private ArrayList<Type> list;
  private ImageView hint_img;
  private GridView listView;
  private Pro_type_adapter adapter;
  private Type type;
  private ProgressBar progressBar;
  private String typename;
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_pro_type, null);
    progressBar=(ProgressBar) view.findViewById(R.id.progressBar);
    hint_img=(ImageView) view.findViewById(R.id.hint_img);
    listView = (GridView) view.findViewById(R.id.listView);
    typename=getArguments().getString("typename");
    ((TextView)view.findViewById(R.id.toptype)).setText(typename);
    GetTypeList();
    adapter=new Pro_type_adapter(getActivity(), list);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {


      }
    });

    return view;
  }


  private void GetTypeList() {
    list=new ArrayList<Type>();
    for(int i=1;i<35;i++){
      type=new Type(i, typename+i, "");
      list.add(type);
    }  
    progressBar.setVisibility(View.GONE);
  }
}

fragment布局代碼

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@color/activity_bg" >


  <TextView 
    android:id="@+id/toptype"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:textSize="12sp"
    android:layout_margin="15dp"
    />

   <GridView
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:numColumns="3"
    android:horizontalSpacing="10dp"
    android:verticalSpacing="10dp"
    android:layout_below="@id/toptype"
    android:scrollbars="none"
     />

  <ImageView
    android:id="@+id/hint_img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="60dp"
    android:contentDescription="@null"
    android:scaleType="centerInside"
    android:visibility="gone" />

  <ProgressBar
    android:id="@+id/progressBar"
    style="@android:style/Widget.ProgressBar.Small"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:visibility="visible" />

</RelativeLayout>

最后自然是fragment適配器代碼啦

package up72.com.testtype;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;


public class Pro_type_adapter extends BaseAdapter {
  private LayoutInflater mInflater;
  private ArrayList<Type> list;
  private Context context;
  private Type type;

  public Pro_type_adapter(Context context, ArrayList<Type> list) {
    mInflater = LayoutInflater.from(context);
    this.list = list;
    this.context = context;
  }

  @Override
  public int getCount() {
    if (list != null && list.size() > 0)
      return list.size();
    else
      return 0;
  }

  @Override
  public Object getItem(int position) {
    return list.get(position);
  }

  @Override
  public long getItemId(int position) {
    return 0;
  }

  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    final MyView view;
    if (convertView == null) {
      view = new MyView();
      convertView = mInflater.inflate(R.layout.list_pro_type_item, null);
      view.icon = (ImageView) convertView.findViewById(R.id.typeicon);
      view.name = (TextView) convertView.findViewById(R.id.typename);
      convertView.setTag(view);
    } else {
      view = (MyView) convertView.getTag();
    }
    if (list != null && list.size() > 0) {
      type = list.get(position);
      view.name.setText(type.getTypename());
      if (type.getTypename().contains("電腦辦公")) {
        view.icon.setBackgroundResource(R.drawable.diannao);
      } else if (type.getTypename().contains("個護(hù)化妝")) {
        view.icon.setBackgroundResource(R.drawable.huazhuang);
      } else if (type.getTypename().contains("鞋靴箱包")) {
        view.icon.setBackgroundResource(R.drawable.nvxie);
      } else if (type.getTypename().contains("潮流女裝")) {
        view.icon.setBackgroundResource(R.drawable.nvzhuang);
      } else if (type.getTypename().contains("圖書")) {
        view.icon.setBackgroundResource(R.drawable.shuji);
      } else if (type.getTypename().contains("玩具樂器")) {
        view.icon.setBackgroundResource(R.drawable.wanju);
      } else if (type.getTypename().contains("音像制品")) {
        view.icon.setBackgroundResource(R.drawable.yingshi);
      } else if (type.getTypename().contains("常用分類")) {
        view.icon.setBackgroundResource(R.drawable.yiyong);
      } else if (type.getTypename().contains("品牌男裝")) {
        view.icon.setBackgroundResource(R.drawable.nanzhuang);
      } else if (type.getTypename().contains("內(nèi)衣配飾")) {
        view.icon.setBackgroundResource(R.drawable.neiyi);
      } else if (type.getTypename().contains("家用電器")) {
        view.icon.setBackgroundResource(R.drawable.dianqi);
      } else if (type.getTypename().contains("手機(jī)數(shù)碼")) {
        view.icon.setBackgroundResource(R.drawable.shouji);
      } else {
        view.icon.setBackgroundResource(R.drawable.nvzhuang);
      }
    }

    return convertView;
  }


  private class MyView {
    private ImageView icon;
    private TextView name;
  }


}

適配器布局代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
   >

  <TextView 
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="15dp"
    android:paddingTop="15dp"
    android:textColor="@android:color/black"
    android:textSize="@dimen/text_mid_size" 
    android:gravity="center"
    />


  <ImageView
    android:id="@+id/line"
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="@color/gray_line_color"
    android:contentDescription="@null"
    android:visibility="visible" />

</LinearLayout>


就這么多了,大家可以直接那去用,效果還是杠杠的。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android調(diào)節(jié)屏幕亮度實(shí)現(xiàn)代碼

    Android調(diào)節(jié)屏幕亮度實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android調(diào)節(jié)屏幕亮度實(shí)現(xiàn)代碼,調(diào)節(jié)屏幕亮度時,先設(shè)置當(dāng)前activity亮度,再并保存為系統(tǒng)亮度即可,本文分別給出兩個步驟的實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-05-05
  • windows10安裝adb/fastboot驅(qū)動超詳細(xì)圖文教程

    windows10安裝adb/fastboot驅(qū)動超詳細(xì)圖文教程

    這篇文章主要介紹了windows10安裝adb/fastboot超詳細(xì)圖文教程,安裝方法也很簡單,只要adb安裝成功,fastboot就安裝好了,文中給大家介紹了問題分析及解決方法,需要的朋友可以參考下
    2023-01-01
  • Android圖片加載的緩存類

    Android圖片加載的緩存類

    這篇文章主要為大家詳細(xì)介紹了Android圖片加載的緩存類的相關(guān)資料,需要的朋友可以參考下
    2016-02-02
  • Android中Fragment管理及重疊問題的解決方法

    Android中Fragment管理及重疊問題的解決方法

    最近做項(xiàng)目碰到了Fragment重疊的問題,后來通過種種方法得以解決了,所以想著總結(jié)下這個問題的解決方法,以及Android中Fragment的管理,方便自己也給有需要的朋友們提供以幫助,感興趣的朋友們下面通過這篇文章一起來學(xué)習(xí)學(xué)習(xí)吧
    2016-11-11
  • Android調(diào)用手機(jī)攝像頭的方法

    Android調(diào)用手機(jī)攝像頭的方法

    這篇文章主要為大家詳細(xì)介紹了Android調(diào)用手機(jī)攝像頭的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Android獲取手機(jī)本機(jī)號碼的實(shí)現(xiàn)方法

    Android獲取手機(jī)本機(jī)號碼的實(shí)現(xiàn)方法

    這篇文章主要介紹了Android獲取手機(jī)本機(jī)號碼的實(shí)現(xiàn)方法的相關(guān)資料,希望通過本文大家能夠?qū)崿F(xiàn)這樣的方法,需要的朋友可以參考下
    2017-10-10
  • Android切面編程知識點(diǎn)詳解

    Android切面編程知識點(diǎn)詳解

    這篇文章給大家整理了關(guān)于Android進(jìn)階資深開發(fā)必備技能-切面編程的相關(guān)知識點(diǎn)內(nèi)容,有興趣的朋友可以參考學(xué)習(xí)下。
    2018-07-07
  • 利用Flutter制作一個會飛的菜單

    利用Flutter制作一個會飛的菜單

    flutter中自帶了drawer組件,可以實(shí)現(xiàn)通用的菜單功能,所以本文將嘗試一下通過自定義動畫來實(shí)現(xiàn)一個會飛的菜單,感興趣的可以了解一下
    2023-06-06
  • Android之PreferenceActivity應(yīng)用詳解

    Android之PreferenceActivity應(yīng)用詳解

    為了引入這個概率 首先從需求說起 即:現(xiàn)有某Activity專門用于手機(jī)屬性設(shè)置 那么應(yīng)該如何做呢
    2012-11-11
  • Android橫向進(jìn)度條演示效果

    Android橫向進(jìn)度條演示效果

    這篇文章主要為大家詳細(xì)介紹了Android橫向進(jìn)度條的演示效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01

最新評論