Android 如何在安卓系统中制作图像字幕?

Android 如何在安卓系统中制作图像字幕?,android,scroll,imageview,horizontal-scrolling,Android,Scroll,Imageview,Horizontal Scrolling,我是Android编程新手,现在我正在尝试将图像放置在水平滚动视图中 实际上我想做的是,我想显示一组需要从右向左自动滚动的图像 到目前为止,我已经尝试如下 <?xml version="1.0" encoding="utf-8"?> <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android

我是Android编程新手,现在我正在尝试将图像放置在水平滚动视图中

实际上我想做的是,我想显示一组需要从右向左自动滚动的图像

到目前为止,我已经尝试如下

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView 
        android:id="@+id/image2"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/icon"
        android:layout_centerHorizontal="true"
        android:layout_marginRight="5px"/>
</LinearLayout>
</HorizontalScroll>

活动文件-

package com.myhorizontalScroll;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;

public class MyHorizontalScrollActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // declare a class field:
            final Handler h = new Handler();

            // later:
            final ImageView scroll=(ImageView)findViewById(R.id.image2);
            Thread t = new Thread(){
                public void run(){
                    int y = scroll.getScrollY();
                    int x = scroll.getScrollX();

                    while(y<1600){
                        // need final values to create anonymous inner class
                        final int X = x;
                        final int Y = y;
                        h.post(new Runnable() {
                            public void run() {
                                scroll.scrollTo(X, Y);
                            }
                        });
                        x++;
                        try {
                            sleep(1000/12);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            };
            t.start();
    }
}
package com.myhorizontalScroll;
导入android.app.Activity;
导入android.os.Bundle;
导入android.os.Handler;
导入android.widget.ImageView;
公共类MyHorizontalScrollActivity扩展活动{
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//声明类字段:
最终处理程序h=新处理程序();
//后来:
最终ImageView滚动=(ImageView)findViewById(R.id.image2);
线程t=新线程(){
公开募捐{
int y=scroll.getScrollY();
int x=scroll.getScrollX();

虽然(y这是我在我的一个应用程序中所做的。这基本上是用来显示喜欢帖子的用户的个人资料图片。你自然需要自己想一想,但我会尽力帮助你

首先,XML:

<LinearLayout
    android:id="@+id/linlaLikesStrip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:visibility="gone" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:text="LIKES BY:"
        android:textColor="#888888"
        android:textSize="14sp"
        android:textStyle="bold" >
    </TextView>

    <HorizontalScrollView
        android:id="@+id/horscoLikes"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:overScrollMode="never"
        android:scrollbars="none" >

        <LinearLayout
            android:id="@+id/linlaLikes"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout>

在我的Java代码中,我对它们进行了全局声明和强制转换,因此您需要做一些计算

JAVA代码:

linlaLikes.removeAllViews();

for (int i = 0; i < arrLikes.size(); i++) {

    final getLikes newLikes = arrLikes.get(i);

    ImageView imgUsers = new ImageView(FeedDetails.this);

    // SET THE IMAGEVIEW DIMENSIONS
    int dimens = 45;
    float density = getResources().getDisplayMetrics().density;
    int finalDimens = (int)(dimens * density);

    LinearLayout.LayoutParams imgvwDimens = new LinearLayout.LayoutParams(finalDimens, finalDimens);
    imgUsers.setLayoutParams(imgvwDimens);

    // SET SCALETYPE
    imgUsers.setScaleType(ScaleType.CENTER_CROP);

    // SET THE MARGIN
    int dimensMargin = 4;
    float densityMargin = getResources().getDisplayMetrics().density;
    int finalDimensMargin = (int)(dimensMargin * densityMargin);

    LinearLayout.LayoutParams imgvwMargin = new LinearLayout.LayoutParams(finalDimens, finalDimens);
    imgvwMargin.setMargins(finalDimensMargin, finalDimensMargin, finalDimensMargin, finalDimensMargin);

    // SET PADDING
//              imgUsers.setPadding(finalDimensMargin, finalDimensMargin, finalDimensMargin, finalDimensMargin);

    // DISPLAY THE IMAGES USING THE PROFILELOADER CLASS
    proLoader.DisplayImage(newLikes.getUserProfilePicture(), imgUsers);

    // ADD THE NEW IMAGEVIEW WITH THE PROFILE PICTURE LOADED TO THE LINEARLAYOUT
    linlaLikes.addView(imgUsers, imgvwMargin);

    imgUsers.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent showProfile = new Intent(getApplicationContext(), WallPost.class);
            showProfile.putExtra("USER_ID", newLikes.getUserID());
            showProfile.putExtra("USER_PROFILE", "USER_PROFILE");
            startActivity(showProfile);
        }
    });
}
linlaLikes.removeallview();
for(int i=0;i
一点解释:

  • arrLikes
    是一个保存配置文件图片的
    ArrayList
    。我在
    for循环中使用
    arrLikes.size()
    来获得正确的数字
  • 我没有在XML中硬编码ImageView(显然,因为所需的数字未知),而是在运行时动态创建所需的数字
  • 然后按照大量的步骤设置
    ImageViews
    的大小,然后设置它们之间的
    Margin
  • 最后,我使用@Fedor的延迟加载在新创建的
    imageview
    中显示配置文件图片

  • 希望这能有所帮助。如果您对上述任何一项有任何困难,请随时询问。

    那么,问题出在哪里?您是一位经验丰富的stackoverflow用户,那么为什么这个问题的标题很糟糕?将其改为:“如何制作图像字幕”或类似的内容(我现在不能做,其他一些编辑正在等待)@user198725878:不要在问题标题中包含标签详细信息。在发布问题之前,请阅读