HorizontalScrollView包裹GridView左右滑动但是GridView前面需要有一个imageview怎么实现

zzh1026it 2016-05-11 12:15:45
我要实现这种界面效果

可以左右滑动
我的方法是HorizontalScrollView包裹GridView左右滑动前面添加一个imageview来实现
<HorizontalScrollView
android:id="@+id/hl_user_photo"
android:layout_width="match_parent"
android:layout_height="@dimen/height_348"
android:layout_marginLeft="@dimen/margin_36"
android:paddingBottom="@dimen/margin_32"
android:scrollbars="none">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>

<ImageView
android:id="@+id/first_image"
android:layout_width="167dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="@drawable/picture_moren" />

<LinearLayout
android:id="@+id/id_gallery"
android:layout_marginLeft="7dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:columnWidth="81dp"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"></GridView>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>

可以实现滑动,但是效果不对....
实际效果是前面的 imageview 不会显示,必须向右拖动才能显示, 我想要的效果是刚出来就显示那个imageview的,但是实际上不会那样显示我的主要代码为:
mHlUserPhoto = (HorizontalScrollView) findViewById(R.id.hl_user_photo);
gridView = (GridView) findViewById(R.id.gridview);
mGallery = (LinearLayout) findViewById(R.id.id_gallery);
mInflater = LayoutInflater.from(this);
adapter = new GridViewAdapter(mImgIds, mGallery, mInflater);
gridView.setAdapter(adapter);

int size = mImgIds.length;
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
float density = dm.density;

int columnsNum = size % 2 == 0 ? size / 2 : size / 2 + 1;
int allWidth = (int) (86 * columnsNum * density);
//int itemWidth = (int) (85 * density);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
allWidth, LinearLayout.LayoutParams.MATCH_PARENT);


gridView.setLayoutParams(params);
//gridView.setColumnWidth(itemWidth);
//gridView.setHorizontalSpacing(10);
gridView.setStretchMode(GridView.NO_STRETCH);
gridView.setNumColumns(columnsNum);


求助各位大神我该怎么改?
...全文
382 7 打赏 收藏 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_29637837 2016-05-16
  • 打赏
  • 举报
回复
<LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="wrap_content"> <ImageView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> <GridView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3"> </GridView> </LinearLayout> 你这样写试试
zzh1026it 2016-05-13
  • 打赏
  • 举报
回复
我要实现这种效果

实际上gridView把imageView挤出去了,出来的效果成了这样

其实那个imageView还是在的,向左滑动是可以出来的


求大神回答一下啊
zzh1026it 2016-05-13
  • 打赏
  • 举报
回复
引用 3 楼 qq_34730552 的回复:
两个view的焦点问题,只要把gridview失去焦点就OK了
失去焦点没有用啊,还是会把那个imageview挤到左边去
zzh1026it 2016-05-13
  • 打赏
  • 举报
回复
引用 2 楼 qq_29637837 的回复:
权重的属性用过吗?你可以试试
不行啊,试了试还是不行, GridView总是会把imageView挤出去
qq_29637837 2016-05-11
  • 打赏
  • 举报
回复
权重的属性用过吗?你可以试试
zzh1026it 2016-05-11
  • 打赏
  • 举报
回复
?求大神来帮助啊
qq_34730552 2016-05-11
  • 打赏
  • 举报
回复
两个view的焦点问题,只要把gridview失去焦点就OK了

80,490

社区成员

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

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