Imageview在android的底部和右侧位置换行

时间:2016-04-23 05:15:25

标签: android

我已经在我的应用程序中实现了标签图像。如果我在布局标签内部触摸图像,则可见。标签图像不会在左侧和顶部位置包裹。但它将包裹在右侧和底部位置。如果我触摸左侧的任何位置,第一张图片显示没有包装。在第二张图片中,标签在右侧包裹。

用于实现标签图像而不包裹在右侧和底部位置。
rr = (RelativeLayout) findViewById(R.id.tagimages);
    rr.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
                case MotionEvent.ACTION_DOWN:

                    searchlayout.setVisibility(View.VISIBLE);
                    int x1 = (int) event.getX();
                    int y = (int) event.getY();
                    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.WRAP_CONTENT,
                            RelativeLayout.LayoutParams.WRAP_CONTENT);
                    lp.setMargins(x1, y, 0, 0);

                        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(250, 100);

                        params.topMargin = y;
                        params.leftMargin = x1;
                        params.bottomMargin = 0;
                        params.rightMargin = 0;
                        //rr.setEnabled(false);

                    if(tag1.getVisibility() == View.INVISIBLE){
                        tag1.setVisibility(View.VISIBLE);
                        rr.removeView(tag1);
                        rr.addView(tag1, params);
                    }
                    else if(tag1.getVisibility() == View.VISIBLE && tag2.getVisibility() == View.INVISIBLE){
                        if(!tag1.getText().equals("Who's this?")){
                            tag2.setVisibility(View.VISIBLE);
                            rr.removeView(tag2);
                            rr.addView(tag2, params);
                        }
                    }
                    else if(tag1.getVisibility() == View.VISIBLE && tag2.getVisibility() == View.VISIBLE ){
                        Toast.makeText(Tagpeople.this, "Maximum of 2 people can be tagged", Toast.LENGTH_SHORT).show();
                    }


                    tag1.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if(tag1.getVisibility() == View.VISIBLE){
                                tag1.setVisibility(View.INVISIBLE);
                                namelist.remove(tag1.getText().toString());
                                idlist.remove(id1);
                                xlist.remove(xaxis1);
                                ylist.remove(yaxis1);
                                tag1.setText("Who's this?");
                                rr.removeView(tag1);
                            }
                        }
                    });

这是布局:

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="#000000"
    android:id="@+id/wholelayouttag1"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.cogzidel.hotfuse.Tagpeople">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:id="@+id/searchlayout"
        android:background="#000000"
        android:visibility="gone">

        <EditText
            android:id="@+id/searchbar"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:padding="10dp"
            android:background="#ffffff"
            android:hint="Search friends"/>

        <Button
            android:id="@+id/cancelsearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel"
            android:textColor="#0039cf"
            android:background="@null"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"/>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/tagimages"
        android:layout_width="wrap_content"
        android:layout_marginTop="50dp"
        android:layout_height="300dp"
        android:layout_below="@+id/layout">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="300dp"
            android:id="@+id/imageView10"
            android:background="@drawable/cam"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentStart="true"
            />

        <TextView
            android:layout_width="120dp"
            android:layout_height="40dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Who's this?"
            android:singleLine="true"
            android:ellipsize="end"
            android:visibility="invisible"
            android:id="@+id/tag1"
            android:gravity="center"
            android:paddingTop="12dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:background="@drawable/ic_tag_show"
            android:drawableRight="@drawable/com_facebook_tooltip_blue_xout"
            android:textColor="@color/white"
            android:layout_marginLeft="0dp"
            android:layout_marginTop="0dp" />
        <TextView
            android:layout_width="120dp"
            android:layout_height="40dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Who's this?"
            android:singleLine="true"
            android:ellipsize="end"
            android:visibility="invisible"
            android:gravity="center"
            android:paddingTop="12dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:background="@drawable/ic_tag_show"
            android:textColor="@color/white"
            android:layout_below="@+id/tag1"
            android:drawableRight="@drawable/com_facebook_tooltip_blue_xout"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_marginRight="50dp"
            android:layout_marginEnd="50dp"
            android:id="@+id/tag2" />


    </RelativeLayout>

</RelativeLayout>

`This position is correct the tag image not wrap on left side

The tag image is wrap on right side.so i need tag image to displayed like as left side

0 个答案:

没有答案