【问题标题】:Android layout: buttons at bottom similar to wechatAndroid布局:底部按钮类似微信
【发布时间】:2015-01-06 11:04:57
【问题描述】:

对于我的应用程序,我试图将按钮放在类似于微信应用程序的所有活动的底部,如下图所示:

现在我想到的一种方法是在每个活动的底部添加<ImageButton>s,但我认为微信不会这样做,因为您可以在活动之间滑动并且没有触发onCreate,活动总是在那里只需在特定按钮上滑动或触摸即可切换。

我做了研究,发现可以使用split action bar 甚至ViewFlipper。操作栏拆分是没有问题的,因为按钮将被移回操作栏,例如在横向模式下,因为我希望按钮总是像微信一样出现在底部。我看到的另一个选项是Tabbed 界面,但我看到它可以出现在操作栏下方,不像微信,甚至操作栏会根据活动进行更改。

问题:有谁知道微信用什么来实现这个功能,所以我可以实现同样的功能?

【问题讨论】:

  • 我不知道微信用于此目的,但可以肯定的是,您可以使用“Tabhost”获得相同的输出。
  • 一个RelativeLayout水平为所有ImageButtons,并对齐底部,你也可以为'RelativeLayout'设置背景颜色
  • 我使用 v4 支持库中的 ViewPager 和我自己在活动底部的按钮做了类似的事情,我自己处理各种回调。我需要支持到 api 级别 8。

标签: android android-layout wechat


【解决方案1】:
here is code main class 


public class TabSample extends TabActivity {
    /** Called when the activity is first created. */

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setTabs();

    }

    private void setTabs() {

        addTab("Wechat", R.drawable.tab_home, ShowList.class);
        addTab("Social", R.drawable.tab_search, UploadVideo.class);

        addTab("Contact Us", R.drawable.tab_home, Contactus.class);
        addTab("Setting", R.drawable.tab_search, DoNotDo.class);




    }

    private void addTab(String labelId, int drawableId, Class<?> c) {
        TabHost tabHost = getTabHost();
        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);

        View tabIndicator = LayoutInflater.from(this).inflate(
                R.layout.tab_indicator, getTabWidget(), false);
        TextView title = (TextView) tabIndicator.findViewById(R.id.title);
        title.setText(labelId);
        ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
        icon.setImageResource(drawableId);

        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }
}

here is xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:background="#ffffff"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dp"
            android:layout_weight="0" />

    </LinearLayout>

</TabHost>

【讨论】:

【解决方案2】:

一个想法是创建BaseActivity,其中包括您在整个应用程序中喜欢的一般设计。在其他活动中,扩展 BaseActivity。您还可以在一些不需要显示按钮的活动中扩展 Activity 类,例如 LoginActivity

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 1970-01-01
    • 2013-11-06
    • 2016-04-17
    • 1970-01-01
    相关资源
    最近更新 更多