开发者

Use image as multiple buttons in Android

开发者 https://www.devze.com 2023-03-21 00:44 出处:网络
I want to use the below image as a five different buttons. In addition, the image must stay at the bottom of the screen. Any ideas 开发者_C百科on how can I accomplish this?

I want to use the below image as a five different buttons. In addition, the image must stay at the bottom of the screen. Any ideas 开发者_C百科on how can I accomplish this?

Use image as multiple buttons in Android


If you want to use just one image, it is possible but harder and it is not the best option because you have to take care of the size according to the devices. But as I said, it is not impossible. You have to detect where the finger did the tap and then, with some maths, decided which "button" was touched.

To detect the tap, you can use "onTouchEvent" or use a "GestureDetector".


That wouldn't work. The best choice would be to split up the images, and use them separately.

You will probably have to have separate images for the dividers as well.


try using this

 tabHost = (TabHost)findViewById(android.R.id.tabhost);
           Intent intent1 = new Intent(this, javaclass.class);
        TabSpec tab1 = tabHost.newTabSpec("tid1");
        ImageView img1 = new ImageView(this);
            img1.setLayoutParams(new LayoutParams(tabWidth, tabHeight));
        img1.setBackgroundColor(Color.TRANSPARENT);
            tab1.setIndicator(img1).setContent(intent1);

and set image as background on xml Layout as below

<RelativeLayout
            android:id="@+id/layTab"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:background="@drawable/image"
            android:layout_alignParentBottom="true"
            android:layout_centerVertical="true"
            >
            <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            />
        </RelativeLayout>


You could look into ImageButtons and define your background. As for splitting up I am unsure but I guess it is always possible to have 1 for each "button" and just align them neatly.


yap, You can use tabSpec as above and then split this images and set to each tabSpec and add this tabSpec into tabHost and set backGround to black its look like this.

0

精彩评论

暂无评论...
验证码 换一张
取 消