Reputation: 229
I have a dynamic event view. In that I have image view and text view. I want to show image view in notification is not null and text view to the right of image view.
For this I have set visibility of image view as gone. So if notification is not null image view should be visible and text view should move to right of image view.
How to achieve this?
Event view layout :
<?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="match_parent"
android:background="@drawable/shape"
android:id="@+id/container"
android:layout_marginLeft="60dp"
android:layout_marginRight="12dp">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:id="@+id/notify"
android:layout_alignParentRight="false"
android:layout_alignParentEnd="false"
android:background="@drawable/sound"
android:layout_marginLeft="05dp"
android:layout_marginTop="04dp"
android:layout_marginRight="05dp"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/textViewTitle"
android:layout_marginTop="01dp"
android:layout_marginLeft="05dp" />
</RelativeLayout>
event view code :
private void createEvent(LayoutInflater inflater, ViewGroup dayplanView, int fromMinutes, int toMinutes, String title,String location,final int id,int color,String notification) {
eventView = inflater.inflate(R.layout.event_view, dayplanView, false);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) eventView.getLayoutParams();
container = (RelativeLayout) eventView.findViewById(R.id.container);
TextView tvTitle = (TextView) eventView.findViewById(R.id.textViewTitle);
list.add(eventView);
ImageView notify = (ImageView) eventView.findViewById(R.id.notify);
((GradientDrawable) eventView.getBackground()).setColor(color);
tvTitle.setTextColor(Color.parseColor("#FFFFFF"));
if (tvTitle.getParent() != null)
((ViewGroup) tvTitle.getParent()).removeView(tvTitle);
if(notification == null)
{
notify.setVisibility(View.VISIBLE);
}
else {
notify.setVisibility(View.GONE);
}
if(location.equals(""))
{
tvTitle.setText("Event : " + title);
} else {
tvTitle.setText("Event : " + title + " (At : " + location +")");
}
int distance = (toMinutes - fromMinutes);
layoutParams.topMargin = dpToPixels(fromMinutes + 9);
layoutParams.height = dpToPixels(distance);
eventView.setLayoutParams(layoutParams);
dayplanView.addView(eventView);
container.addView(tvTitle);
eventView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i = new Intent(getActivity(), AddEventActivity.class);
editMode = true;
i.putExtra("EditMode", editMode);
i.putExtra("id", id);
startActivityForResult(i, 1);
}
});
}
Now the image view is shown above the text view. How to move text view right to image view if it is visible?
Upvotes: 0
Views: 1803
Reputation: 1579
Do this:
ImageView notify = new ImageView(getContext());
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) notify.getLayoutParams();
params.addRule(RelativeLayout.RIGHT_OF, R.id.notify);
Upvotes: 0
Reputation: 1354
Just add this attribute in your textview
android:layout_toRightOf="@+id/notify"
Upvotes: 1