如何在 android 中的图像滑块的视图寻呼机底部创建叠加层
How to create overlay at the bottom of view pager for image slider in android
我想为 Image Slider 进行布局,因此必须创建视图分页器并在视图分页器的底部制作一个叠加层。
如何为图像滑块创建该布局。
正如我上面提到的图像那样想要在 android 中进行布局
提前致谢
这是 xml 代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<ImageView
android:id="@+id/selected"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/gallery_relative_layout"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:layout_marginTop="30dip"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000"
android:layout_marginTop="300dp"
android:layout_above="@+id/gallery_relative_layout"
/>
<RelativeLayout
android:id="@+id/gallery_relative_layout"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:paddingTop="20dp">
<HorizontalScrollView
android:id="@+id/hor_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="@+id/gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im1"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im2"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im3"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im4"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im5"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im6"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im7"
android:onClick="biggerView"/>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
</RelativeLayout>
这是 MainActivity.java 代码:
public class MainActivity extends Activity {
ImageView im;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void biggerView(View v)
{
im=(ImageView)findViewById(R.id.selected);
switch (v.getId())
{
case R.id.image1: im.setImageResource(R.drawable.im1);
break;
case R.id.image2: im.setImageResource(R.drawable.im2);
break;
case R.id.image3: im.setImageResource(R.drawable.im3);
break;
case R.id.image4: im.setImageResource(R.drawable.im4);
break;
case R.id.image5: im.setImageResource(R.drawable.im5);
break;
case R.id.image6: im.setImageResource(R.drawable.im6);
break;
case R.id.image7: im.setImageResource(R.drawable.im7);
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
这里是输出:
当你点击任何图片时,它显示如下。
注意:这里我用了我的图片,用了你的图片,看看结果。
您可以使用底部的回收站视图。并添加一个水平滚动的 LinearLayoutManager。在您的适配器中添加单个项目图像视图。它一定会帮助你:)
我以前用过这样的组件。
基本上这些代码对你来说应该足够了。其实不需要很复杂。
这些是您的布局代码。我相信您会根据需要在 java 代码中使用它们。
这是 horizontalListView 的 link:
https://github.com/sephiroth74/HorizontalVariableListView
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffAAAAAA" />
<!--You may use here-->
<!--HorizontalListView or-->
<!--RecyclerView with horizontal layoutManager-->
<!--I would use HorizontalListView it's easier-->
<!--You may find it by searching in google-->
<HorizontalListView
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:layout_height="150dp"
android:background="#66FFffFF" />
</FrameLayout>
编码愉快。
我想为 Image Slider 进行布局,因此必须创建视图分页器并在视图分页器的底部制作一个叠加层。
如何为图像滑块创建该布局。
正如我上面提到的图像那样想要在 android 中进行布局 提前致谢
这是 xml 代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<ImageView
android:id="@+id/selected"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/gallery_relative_layout"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:layout_marginTop="30dip"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000"
android:layout_marginTop="300dp"
android:layout_above="@+id/gallery_relative_layout"
/>
<RelativeLayout
android:id="@+id/gallery_relative_layout"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:paddingTop="20dp">
<HorizontalScrollView
android:id="@+id/hor_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="@+id/gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im1"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im2"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im3"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im4"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im5"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im6"
android:onClick="biggerView"/>
<ImageView
android:id="@+id/image7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/im7"
android:onClick="biggerView"/>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
</RelativeLayout>
这是 MainActivity.java 代码:
public class MainActivity extends Activity {
ImageView im;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void biggerView(View v)
{
im=(ImageView)findViewById(R.id.selected);
switch (v.getId())
{
case R.id.image1: im.setImageResource(R.drawable.im1);
break;
case R.id.image2: im.setImageResource(R.drawable.im2);
break;
case R.id.image3: im.setImageResource(R.drawable.im3);
break;
case R.id.image4: im.setImageResource(R.drawable.im4);
break;
case R.id.image5: im.setImageResource(R.drawable.im5);
break;
case R.id.image6: im.setImageResource(R.drawable.im6);
break;
case R.id.image7: im.setImageResource(R.drawable.im7);
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
这里是输出:
当你点击任何图片时,它显示如下。
注意:这里我用了我的图片,用了你的图片,看看结果。
您可以使用底部的回收站视图。并添加一个水平滚动的 LinearLayoutManager。在您的适配器中添加单个项目图像视图。它一定会帮助你:)
我以前用过这样的组件。
基本上这些代码对你来说应该足够了。其实不需要很复杂。
这些是您的布局代码。我相信您会根据需要在 java 代码中使用它们。
这是 horizontalListView 的 link: https://github.com/sephiroth74/HorizontalVariableListView
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffAAAAAA" />
<!--You may use here-->
<!--HorizontalListView or-->
<!--RecyclerView with horizontal layoutManager-->
<!--I would use HorizontalListView it's easier-->
<!--You may find it by searching in google-->
<HorizontalListView
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:layout_height="150dp"
android:background="#66FFffFF" />
</FrameLayout>
编码愉快。