Designing Layout like iphone in android

我怕爱的太早我们不能终老 提交于 2019-12-24 09:38:44

问题


I want to design something like this in android..See the Buttons Bar -> New Deals, NewCoupons, New Categories.

Again see the top portion of that Buttons Bar -> Its something like horizontal scroll view.

How to design such type of layouts in android. ?


回答1:


See this class http://code.google.com/p/deezapps-widgets/ for implementing a horizontal scroll view.

The buttons bar can be implemented using a TabWidget as Phonon suggests.

To implement a button bar

  1. Call tabSpec.setIndicator(buildIndicator(tabName))
  2. Build your view with something like:

    private View buildIndicator(String text) {
        final TextView indicator = (TextView) getLayoutInflater().inflate(R.layout.tab_indicator, null);
        indicator.setText(text);
        return indicator;
    }
    
  3. tab_indicator.xml:

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tab_label"
    android:layout_width="0dip"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:textColor="@color/white"
    android:gravity="center"
    android:textSize="14sp"
    android:textStyle="bold"
    android:minHeight="38dp"
    android:background="@drawable/bgtab"/>
    
  4. bgtab is a selector drawable with

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="true"
        android:drawable="@drawable/bg_tab_default"
        />
    <item
        android:state_selected="false"
        android:state_focused="false"
        android:state_pressed="false"
        android:drawable="@drawable/bg_tab_default"
        />
    <item       
        android:state_selected="true"
        android:state_focused="false"
        android:state_pressed="false"
        android:drawable="@drawable/bg_tab_selected"
        />
    <item
        android:state_focused="true"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/bg_tab_selected"
        />
    

This is mostly from the Google I/O app. bg_tab_selected/default will be 9-patch PNGs which when expanded will be shaped like buttons.




回答2:


For the "Horizontal ScrollView", look up ViewFlipper. It's much more like what you're asking about. The coupons/deals/categories can be implemented with TabWidget (basically a tabbed view) with custom Tab images that look like buttons.



来源:https://stackoverflow.com/questions/5432029/designing-layout-like-iphone-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!