- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 SlidingTabs
创建两个选项卡。选项卡的 UI 应如下所示 -
当第一个选项卡被选中时
选择第二个选项卡时。
(请注意蓝色矩形的直角)
我正在使用以下选择器来创建上面显示的 UI。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active tab -->
<item android:state_selected="true" android:state_focused="false"
android:state_pressed="false" android:drawable="@drawable/round_corner_rectangle" />
<!-- Inactive tab -->
<item android:state_selected="false" android:state_focused="false"
android:state_pressed="false" android:drawable="@android:color/transparent" />
<!-- Pressed tab -->
<item android:state_pressed="true" android:state_selected="true" android:drawable="@drawable/round_corner_rectangle" />
<item android:state_pressed="true" android:state_selected="false" android:drawable="@color/transparent" />
<!-- Selected tab (using d-pad) -->
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@android:color/transparent" />
</selector>
round_corner_rectangle
的代码如下-
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp"/>
<solid android:color="@color/login_background" />
</shape>
login_background
是深蓝色。使用上面的代码,我得到以下结果-
当然,我可以从 round_corner_rectangle
中删除 corner
项,使深蓝色背景笔直而不是圆形。 If I make right side of blue rectangle straight, when the other tab is selected, the rectangle is rounded on wrong side.
我应该怎么做才能获得如第一张图片所示的 UI?
更新:-正如您从我的代码中看到的那样,我在创建圆角方面没有问题,问题是在所选选项卡上有直角。 If I simply add round corners, when a second tab is selected, the corners are rounded on the wrong side.
最佳答案
好的,首先创建这个简单的矩形可绘制 xml。并且不要担心我们将动态创建的角。
tabbackground.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="your_color" />
<size android:height="40dp" />
</shape>
现在当你改变标签时。您必须使用 selectedTabPosition 变量中的监听器来检索所选选项卡的位置。我不是在写完整的代码,只是给你一个骨架
if (selectedTabPosition == 0) { // that means first tab
GradientDrawable drawable = (GradientDrawable) getResources().getDrawable(R.drawable.tabbackground);
drawable.setCornerRadii(new float[]{30,30,0,0,0,0,30,30}); // this will create the corner radious to left side
} else if (selectedTabPosition == your_total_tabcount) { // that menas it's a last tab
GradientDrawable drawable = (GradientDrawable) getResources().getDrawable(R.drawable.tabbackground);
drawable.setCornerRadii(new float[]{0,0,30,30,30,30,0,0}); // this will create the corner radious to right side
} else { // you don't have to worry about it. it is only used if you have more then 2 tab. means for all middle tabs
GradientDrawable drawable = (GradientDrawable) getResources().getDrawable(R.drawable.tabbackground);
drawable.setCornerRadii(new float[]{0,0,0,0,0,0,0,0}); // this will remove all corner radious
}
// and at last don't forget to set this drawable.
这是我尝试过的按钮点击
关于带有圆角的 Android SlidingTabs 样式选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31488785/
我如何使用 SlidingTabLayout 将图标放入我的选项卡中。我只想将标题更改为图标。请帮助我如何去做。 代码如下ViewPagerAdapter.java import android.su
我正在使用 SlidingTabs 创建两个选项卡。选项卡的 UI 应如下所示 - 当第一个选项卡被选中时 选择第二个选项卡时。 (请注意蓝色矩形的直角) 我正在使用以下选择器来创建上面显示的 UI。
在简单的锁定屏幕上解锁我的 android 2.3.3 手机时,一旦触摸 slider ,它就会振动,当 slider 被完全拉到另一边时,它会振动一次。 我觉得它有点烦人,所以我想我可以在设置中以某
作为新手,我尝试在滑动选项卡中使用图标而不是 TextView 。问题是,当我更改选项卡时,我的一个 fragment (MapFragment) 使应用程序崩溃。我知道我可以创建 onDestroy
我在将 CardView 添加到我的选项卡内容时遇到问题,所以这里是完整的故事:1.Created滑动标签,有3个标签。2.为每个选项卡( tab_1, tab_2, tab_3 .3.为他们设置一个
预先感谢您花时间解决我的问题。 我有 2 个 Activity : Activity A 和 Activity B。 Activity A 调用 Activity B。 Activity B 是 Sl
我是一名优秀的程序员,十分优秀!