简体   繁体   English

如何通过代码使这张照片动态加权?

[英]How can i make this photos dynamic weight by code?

I want that the pic will be dynamically like if I use this method 3 times it will give me 3 photos and the weight will be dynamic 我希望图片会像我使用此方法3次一样动态,它将给我3张照片,并且重量会动态变化

public void addImageToRaw(final String text, final float rate/*, final TextView textView*/, final PhotosRatingInfo photosRatingInfo)
{
         ImageView imageView = new ImageView(rawLinear1.getContext());
            imageView.setImageBitmap(BitmapFactory.decodeFile(text));
            //imageView.setLayoutParams();
        //PhotosRatingInfo ratingInfo = new PhotosRatingInfo(rate, text);

        rawLinear1.addView(imageView, 150, 150);

        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                //MainMenuActivity.Chasttext();

                RateDialog dialog = new RateDialog(text, rate/*, textView*/, photosRatingInfo);
                dialog.show(manager, "");

                //new RateDialog().show(manager, "");

            }
        });
}

一种

An alternative to achieve this would be using a GridView. 实现此目的的替代方法是使用GridView。 That's the best way, as you get the same solution. 这是最好的方法,因为您获得相同的解决方案。

In your layout.xml you can set a value for weight. 在您的layout.xml中,您可以设置一个权重值。 You can only do this for one row (you could just create as many seperate rows as you need. 您只能对一行执行此操作(您可以根据需要创建任意数量的独立行。

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="3">

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    </LinearLayout>

Otherwise, if you really want a grid, you would need to use a GridView, but that requires Android OS 4.3+. 否则,如果您确实想要网格,则需要使用GridView,但这需要Android OS 4.3+。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM