如果imageview在android中消失,如何从左边设置textview

时间:2014-09-15 05:29:25

标签: android android-layout textview imageview

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

    <com.lociiapp.utils.RoundedImageView
        android:id="@+id/notificationuserimage"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="20dp"
        android:layout_marginBottom="10dip" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/notificationuserimage"
        android:layout_toEndOf="@+id/notificationuserimage"
        android:layout_toRightOf="@+id/notificationuserimage"
        android:paddingBottom="10dp"
        android:text="Request for traveling"
        android:textColor="#282e36"
        android:textSize="23px"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/title"
        android:layout_alignStart="@+id/title"
        android:layout_below="@+id/title"
        android:text="asd has requested to travel with you"
        android:textColor="#282e36"
        android:textSize="23px" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignBottom="@+id/notificationuserimage"
        android:layout_toEndOf="@+id/notificationuserimage"
        android:layout_toRightOf="@+id/notificationuserimage"
        android:src="@drawable/accepticon" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignTop="@+id/imageView1"
        android:layout_toEndOf="@+id/imageView1"
        android:layout_toRightOf="@+id/imageView1"
        android:src="@drawable/rejecticon" />

    <TextView
        android:id="@+id/rejectedrequest"
        android:layout_width="wrap_content"
        android:layout_height="40dip"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/revresetime"
        android:singleLine="true"
        android:text="Rejected"
        android:visibility="invisible" />

    <ImageView
        android:id="@+id/runnimage"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignTop="@+id/revresetime"
        android:layout_toLeftOf="@+id/rejectedrequest"
        android:layout_toStartOf="@+id/rejectedrequest"
        android:src="@drawable/drive"
        android:visibility="invisible" />

    <TextView
        android:id="@+id/revresetime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView2"
        android:layout_alignTop="@+id/imageView2"
        android:layout_toEndOf="@+id/imageView2"
        android:layout_toRightOf="@+id/imageView2"
        android:gravity="center_vertical"
        android:text="Just 5 Minute Ago"
        android:textColor="#8f939b"
        android:textSize="23px" />

</RelativeLayout>   

这是通知列表项Xml:

的代码
public class Notifcationadapter extends BaseAdapter {
    private static ArrayList<Notify> values;
    Context context;
    String senderid;
    String imagepath;
    String member_id;
    String recevr_id;
    String jsonResp;

    // List<RowItem> rowItems;
    ViewHolder holder = null;
    LinearLayout linear2;
    DataBaseManager dbManager = new DataBaseManager(context);
    ArrayList<Notify> notifies;

    public Notifcationadapter(Context context, ArrayList<Notify> notifies) {
        super();
        this.context = context;
        this.notifies = notifies;

    }

    /* private view holder class */
    private class ViewHolder {

        TextView txtTitle;
        TextView txtDesc;
        ImageView yesimage;
        ImageView noimage;
        TextView revresetime;
        TextView rejected;
        ImageView runnimage;
        ImageView notificationuserimage;
        LinearLayout linear2;

    }

    public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.notifcationlistitem,
                    parent, false);
            holder = new ViewHolder();
            // holder.linear2 = (LinearLayout) convertView
            // .findViewById(R.id.linear2);
            holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);

            holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
            holder.yesimage = (ImageView) convertView
                    .findViewById(R.id.imageView1);
            holder.noimage = (ImageView) convertView
                    .findViewById(R.id.imageView2);
            holder.revresetime = (TextView) convertView
                    .findViewById(R.id.revresetime);
            holder.rejected = (TextView) convertView
                    .findViewById(R.id.rejectedrequest);
            holder.notificationuserimage = (ImageView) convertView
                    .findViewById(R.id.notificationuserimage);

            holder.runnimage = (ImageView) convertView
                    .findViewById(R.id.runnimage);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // holder.txtTitle.setText("Title");
        String statustype = notifies.get(position).getNotificationType();

        if (statustype.equals("1")) {
            holder.txtTitle.setText("Request For travelling");
            holder.txtDesc.setText(notifies.get(position)
                    .getNotificationDescrpiton());

            holder.revresetime.setText(Functions
                    .setLastSeenNotifcationTime(notifies.get(position)
                            .getNotificationDatetime()));

            senderid = notifies.get(position).getNotificationSenderID();
            imagepath = "http://api.lociiapp.com/TransientStorage/"

            + senderid + ".jpg";
            AQuery aq = new AQuery(context);

            aq.id(holder.notificationuserimage).image(imagepath);

            holder.yesimage.setVisibility(View.VISIBLE);
            holder.noimage.setVisibility(View.VISIBLE);

            holder.yesimage.setTag(convertView);
            holder.yesimage.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    View parentView = (View) arg0.getTag();
                    View view = parentView.findViewById(R.id.imageView1);
                    view.setVisibility(View.GONE);
                    view = parentView.findViewById(R.id.imageView2);
                    view.setVisibility(View.GONE);
                    // view = parentView.findViewById(R.id.linear2);
                    view.setVisibility(View.INVISIBLE);
                    view = parentView.findViewById(R.id.runnimage);
                    view.setVisibility(View.INVISIBLE);

                    new sendMesgTask().execute("Acepted");
                    Toast.makeText(context, "Yes", 10000).show();

                }
            });
            holder.noimage.setTag(convertView);
            holder.noimage.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    View parentView = (View) v.getTag();
                    View view = parentView.findViewById(R.id.imageView1);
                    view.setVisibility(View.GONE);
                    view = parentView.findViewById(R.id.imageView2);
                    view.setVisibility(View.GONE);
                    view = parentView.findViewById(R.id.rejectedrequest);
                    view.setVisibility(View.VISIBLE);
                    Toast.makeText(context, "NO", 10000).show();
                    // holder.linear2.setVisibility(View.INVISIBLE);

                    new sendMesgTask().execute("Rjected");
                    holder.yesimage.setVisibility(View.GONE);
                    holder.noimage.setVisibility(View.GONE);
                    holder.rejected.setVisibility(View.VISIBLE);
                }
            });

        }

        else if (statustype.equals("2")) {

            holder.txtDesc.setText(notifies.get(position)
                    .getNotificationDescrpiton());
            holder.txtTitle.setText("Post");
            holder.revresetime.setText(Functions
                    .setLastSeenNotifcationTime(notifies.get(position)
                            .getNotificationDatetime()));

            holder.runnimage.setVisibility(View.VISIBLE);

            senderid = notifies.get(position).getNotificationSenderID();
            imagepath = "http://api.lociiapp.com/TransientStorage/"

            + senderid + ".jpg";
            AQuery aq = new AQuery(context);
            aq.id(holder.notificationuserimage).image(imagepath);

            holder.yesimage.setVisibility(View.GONE);
            holder.noimage.setVisibility(View.GONE);
        }

        else {
            holder.txtDesc.setText(notifies.get(position)
                    .getNotificationDescrpiton());
            holder.txtTitle.setText("Accept/ Reject ");
            holder.txtDesc.setTextColor(Color.RED);
            holder.yesimage.setVisibility(View.GONE);
            holder.noimage.setVisibility(View.GONE);
            holder.revresetime.setText(Functions
                    .setLastSeenNotifcationTime(notifies.get(position)
                            .getNotificationDatetime()));
            senderid = notifies.get(position).getNotificationSenderID();
            imagepath = "http://api.lociiapp.com/TransientStorage/" + senderid
                    + ".jpg";
            AQuery aq = new AQuery(context);
            aq.id(holder.notificationuserimage).image(imagepath);

        }
        String notifcationsenderid = notifies.get(position)
                .getNotificationSenderID();
        String notisread = notifies.get(position).getNotificationStatus();
        if (notisread.equals("false")) {

            convertView.setBackgroundColor(Color.parseColor("#f5f6f1"));
        } else {
            convertView.setBackgroundColor(Color.parseColor("#ffffff"));
        }

        return convertView;
    }

    @Override
    public int getCount() {
        return notifies.size();
    }

    @Override
    public Object getItem(int position) {
        return notifies.get(position).getNotificationType();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    }
}

enter image description here

在具有喜欢和不喜欢的按钮的给定屏幕项目中,日期是图像的右侧像不喜欢但是当隐藏ImageView时日期和时间到顶部甚至你可以看到在帖子项目中日期和时间出现在顶部。我需要建议如何实现这一目标。

2 个答案:

答案 0 :(得分:0)

我认为你的情况不需要的布局太多了,我建议先尝试减少布局。
现在,替换

    android:layout_alignBottom="@+id/imageView2"
    android:layout_alignTop="@+id/imageView2"
    android:layout_toEndOf="@+id/imageView2"
    android:layout_toRightOf="@+id/imageView2"

in

 <TextView
        android:id="@+id/revresetime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView2"
        android:layout_alignTop="@+id/imageView2"
        android:layout_toEndOf="@+id/imageView2"
        android:layout_toRightOf="@+id/imageView2"
        android:gravity="center_vertical"
        android:text="Just 5 Minute Ago"
        android:textColor="#8f939b"
        android:textSize="23px" />

android:layout_toRightOf="@+id/notificationuserimage"
android:layout_above="@+id/thelayoutwithtext"Post"inyourimage"

答案 1 :(得分:0)

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff"
    android:orientation="horizontal" >
     <com.lociiapp.utils.RoundedImageView
        android:id="@+id/notificationuserimage"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="20dp"
        android:layout_marginBottom="10dip" />

    <LinearLayout
            android:id="@+id/motherLayout"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"

        android:orientation="vertical" >

         <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/notificationuserimage"
        android:layout_toEndOf="@+id/notificationuserimage"
        android:layout_toRightOf="@+id/notificationuserimage"
        android:paddingBottom="10dp"
        android:text="Request for traveling"
        android:textColor="#282e36"
        android:textSize="23px"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/title"
        android:layout_alignStart="@+id/title"
        android:layout_below="@+id/title"
        android:text="asd has requested to travel with you"
        android:textColor="#282e36"
        android:textSize="23px" />

          <LinearLayout
            android:id="@+id/motherLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:orientation="horizontal" >
        <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignBottom="@+id/notificationuserimage"
        android:layout_toEndOf="@+id/notificationuserimage"
        android:layout_toRightOf="@+id/notificationuserimage"
        android:src="@drawable/accepticon" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignTop="@+id/imageView1"
        android:layout_toEndOf="@+id/imageView1"
        android:layout_toRightOf="@+id/imageView1"
        android:src="@drawable/rejecticon" />

    <TextView
        android:id="@+id/rejectedrequest"
        android:layout_width="wrap_content"
        android:layout_height="40dip"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/revresetime"
        android:singleLine="true"
        android:text="Rejected"
        android:visibility="invisible" />

    <ImageView
        android:id="@+id/runnimage"
        android:layout_width="wrap_content"
        android:layout_height="25dip"
        android:layout_alignTop="@+id/revresetime"
        android:layout_toLeftOf="@+id/rejectedrequest"
        android:layout_toStartOf="@+id/rejectedrequest"
        android:src="@drawable/drive"
        android:visibility="invisible" />

    <TextView
        android:id="@+id/revresetime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView2"
        android:layout_alignTop="@+id/imageView2"
        android:layout_toEndOf="@+id/imageView2"
        android:layout_toRightOf="@+id/imageView2"
        android:gravity="center_vertical"
        android:text="Just 5 Minute Ago"
        android:textColor="#8f939b"
        android:textSize="23px" />

 </LinearLayout>

 </LinearLayout>
</LinearLayout>