请问关于关于fragment +viewpage,显示问题

langkejianxin1999 2015-01-29 05:02:19
请问,使用fragment+viewpage, 显示如图 1所示, 但是 那跟 “蓝线”并不在字体下面,请问应该怎么处理呢?
麻烦会的朋友帮忙回复下吧,谢啦

图一

想要的效果如下图 2:(“修改” 和 “显示” 要靠左边些,然后 当滑动的时候,底线要刚好在 “修改”或者 “显示”的下边 )


图2

public class ProfessionalActivity extends FragmentActivity {
。。。
private void InitViewPager() {
mViewpager = (ViewPager) findViewById(R.id.forumpager);
fragmentsList = new ArrayList<Fragment>();
leFragment = new leFragment();
nalFragment = new nalFragment( ); //两个fragment


fragmentsList.add(leFragment);
fragmentsList.add(nalFragment);

mViewpager.setAdapter(new ProfessionalFragmentPagerAdapter(getSupportFragmentManager(),fragmentsList)); //viewpage
mViewpager.setCurrentItem(0);
mViewpager.setOnPageChangeListener(new MyOnPageChangeListener());
}

private void InitWidth() {
BottomLine = (ImageView)findViewById(R.id.bottom_line); // 蓝线
bottomlinewidth = BottomLine.getLayoutParams().width;
Log.d(TAG,"cursor imageview width="+bottomlinewidth);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenwidth = dm.widthPixels;
position_one = (int)(screenwidth / 2.0);
}

public class MyOnPageChangeListener implements OnPageChangeListener {
@Override
public void onPageSelected(int arg0) {
Animation animation = null;
switch ( arg0 ) {
case 0:
if ( currIndex == 1 ) {
animation = new TranslateAnimation(position_one, 0, 0, 0);
textview_professional.setTextColor(resources.getColor(R.color.lightwhite));
}
textview_article.setTextColor(resources.getColor(R.color.white));
break;
case 1:
if ( currIndex == 0 ) {
animation = new TranslateAnimation(0, position_one, 0, 0);
textview_article.setTextColor(resources.getColor(R.color.lightwhite));
}
textview_professional.setTextColor(resources.getColor(R.color.white));
break;
}
currIndex = arg0;
animation.setFillAfter(true);
animation.setDuration(300);
BottomLine.startAnimation(animation);
}

XML 布局文件如下:
<?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:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/coral"
android:paddingBottom="10dip"
android:paddingTop="10dip" >
<TextView
android:id="@+id/textview_article"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:gravity="center"
android:text="@string/article"
android:textColor="@color/white"
android:textSize="18sp" />
<TextView
android:id="@+id/textview_professional"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:gravity="center"
android:text="@string/professional"
android:textColor="@color/lightwhite"
android:textSize="18sp" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical"
android:paddingBottom="3dip" >
<ImageView
android:id="@+id/bottom_line"

android:layout_width="40dip"
android:layout_height="2dip"
android:layout_marginLeft="20dip"
android:scaleType="matrix"
android:src="#8EE" />
</LinearLayout>

<android.support.v4.view.ViewPager
android:id="@+id/forumpager"

android:layout_width="wrap_content"
android:layout_height="221dp"
android:layout_gravity="center"
android:layout_weight="0.67"
android:background="#FFFFFF"
android:flipInterval="30"
android:persistentDrawingCache="animation" />
</LinearLayout>



}
...全文
254 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
浅笑_JIE 2015-01-31
  • 打赏
  • 举报
回复
在布局的时候TextView下面加个ImageView 当你点击不同按钮时 在代码中对控件做相对应的设置
zhaojiaxing910817 2015-01-30
  • 打赏
  • 举报
回复
先把textview画到左边,变成图2那样子,然后你是想用动画显示平移,看上去像是fragment换页绑定imageview的效果,你要想这么干 你平移就好了 ,把起始位置和结束位置拿到用translate平移就行。我想说 你为什么不直接用radioButton和fragment互相绑定,选中替换radioButton上的图片就好了。 如果你非要imageview那样的横条显示 你可以拿个第三方代码 直接实现 做的好看又省事啊
  • 打赏
  • 举报
回复
最简单的方法,把上面的那个textView和下面的蓝色细线写在一起Layou里,点击哪个tab,就让textview和蓝色细线一起显示,另一个textview和蓝色细线隐藏。至于蓝色细线建议就一个View控件就行了,别整什么ImageView之类的..
langkejianxin1999 2015-01-30
  • 打赏
  • 举报
回复
麻烦会的朋友帮忙回复下 谢啦
langkejianxin1999 2015-01-30
  • 打赏
  • 举报
回复
麻烦会的朋友帮忙回复下吧,谢谢啦
gdutqiang 2015-01-30
  • 打赏
  • 举报
回复
@ zhaojiaxing91... 谢谢您的回复 对于这个 “如果你非要imageview那样的横条显示 你可以拿个第三方代码 直接实现 做的好看又省事啊 请问 能给个链接吗? 谢啦
它通过读取 Excel 表格中的业务数据,结合 Word 模板,自动生成多个独立的合同文件,并自动处理了表格中“合计”行的合并与中文大写金额转换。 资源名称:合同文档自动化生成脚本 (1.py) 名字真是乱起 核心功能:Excel 数据读取 → Word 模板渲染 → 表格单元格合并与金额处理 → 批量导出 Word 文档。 适用场景:财务、销售或行政部门需要根据订单或业务明细,批量制作格式统一的合同、报价单或结算单。 1. 自动把“钱”变成“大写” 它干了啥:它内置了一个翻译功能,专门把阿拉伯数字(比如 100.50)自动转换成财务专用的中文大写(比如 壹佰元伍角)。 为什么有用:写合同最怕手滑写错金额,或者大写格式不对。这个功能全自动搞定,既标准又不会出错。 2. 自动“装修”表格底部 它干了啥:生成文档后,它会自动找到表格的最后一行,把前几列合并成一个大格子,写上“合计:XXX(大写金额)”,并在最右边填上具体的数字总额。 为什么有用:平时我们做完表格,还得手动去合并单元格、算总数、填大写,非常繁琐。这个脚本直接一步到位,把表格收尾工作做得漂漂亮亮。 3. 像“发传单”一样批量做合同 它干了啥:它会看你的 Excel 表格,按照“编号”把数据归类。 如果是同一个编号的货物,它会把它们塞进同一个合同里(比如一个客户买了三样东西,会自动列三行)。 如果是不同的编号,它就生成不同的合同文件。 为什么有用:不管你有一百个还是一千个订单,它都能自动拆分,给每个客户生成一份独立的、内容准确的合同,完全不用人工去复制粘贴。

80,488

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧