Parse automatically logs out Android - java

I am having a strange issue where my app automatically logs me out when I open a certain fragment. I have even tried commenting out all the code to stop this from happening but the issue still occurs. I have included my empty class and XML for the fragment. I can only assume it is a silly issue I have overlooked but I have been trying to find the answer for a good few days.
Appreciate any help
fragment_edit_profile
<merge 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">
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/profileImage"
android:layout_marginTop="25dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/profileImage"
android:layout_centerHorizontal="true"
android:text="Change profile picture"
android:textSize="18sp"
android:id="#+id/changeProfilePictureTextView"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="50dp"
android:layout_below="#id/changeProfilePictureTextView"
android:background="#drawable/white_and_grey_border_bottom"
android:id="#+id/relativeLayout1">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/ic_action_compose"
android:layout_centerVertical="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="45dp"
android:id="#+id/usernameEditTextEditProfile"
android:hint="#string/change_username"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="50dp"
android:layout_below="#id/relativeLayout1"
android:background="#drawable/white_and_grey_border_bottom"
android:id="#+id/relativeLayout2">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/ic_action_compose"
android:layout_centerVertical="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="45dp"
android:hint="Change email address"
android:id="#+id/emailEditTextEditProfile"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="50dp"
android:layout_below="#id/relativeLayout2"
android:background="#drawable/white_and_grey_border_bottom"
android:id="#+id/relativeLayout3">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/ic_action_compose"
android:layout_centerVertical="true"
android:id="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="45dp"
android:layout_centerVertical="true"
android:text="Click here to reset password"
android:textStyle="italic"
android:textSize="18sp"
android:id="#+id/changePassword"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
EditPrfileFragment
public class EditProfileFragment extends Fragment implements View.OnClickListener {
private static final String TAG = "EditProfileFragment";
String password;
String passwordConfirm;
private EditText passwordEditText;
private EditText passwordConfirmEditText;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_edit_profile, container, false);
return view;
}
#Override
public void onClick(View v) {
}

Replace your code with below code.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<ImageView
android:id="#+id/profileImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
<TextView
android:id="#+id/changeProfilePictureTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/profileImage"
android:layout_centerHorizontal="true"
android:text="Change profile picture"
android:textSize="18sp" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#id/changeProfilePictureTextView"
android:layout_marginTop="50dp"
android:background="#drawable/white_and_grey_border_bottom">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:background="#drawable/ic_action_compose" />
<EditText
android:id="#+id/usernameEditTextEditProfile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="45dp"
android:hint="#string/change_username"
tools:ignore="RtlCompat" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#id/relativeLayout1"
android:layout_marginTop="50dp"
android:background="#drawable/white_and_grey_border_bottom">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:background="#drawable/ic_action_compose" />
<EditText
android:id="#+id/emailEditTextEditProfile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="45dp"
android:hint="Change email address"
tools:ignore="RtlCompat" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout3"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#id/relativeLayout2"
android:layout_marginTop="50dp"
android:background="#drawable/white_and_grey_border_bottom">
<ImageView
android:id="#+id/imageView"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:background="#drawable/ic_action_compose" />
<TextView
android:id="#+id/changePassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="45dp"
android:text="Click here to reset password"
android:textSize="18sp"
android:textStyle="italic"
tools:ignore="RtlCompat" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>

Related

When one object is clicked, two listeners are fired

Good day!
I made two cards using **CardView**, then each of them has a **Title** and a **body**. The body should expand when you click on the title. But when you click on "*carsCollapse*", "*socketsCollapse*" also fires. This can be seen on the video. Also, for clarity, I made a Toast, so we can see that when you click on carsCollapse, "*Cars*" and "*Sockets*" appear.
Video: THE LINK
Here is the xml code (shortened version):
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MapFilterFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
app:cardElevation="10dp"
app:contentPadding="20dp">
<LinearLayout
android:animateLayoutChanges="true"
android:id="#+id/carsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/carsCollapse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:src="#drawable/ic_baseline_electric_car_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Cars"
android:textSize="26sp"
android:textStyle="bold"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:id="#+id/carsFilters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
// SOMETHING IN
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
app:cardElevation="10dp"
app:contentPadding="20dp">
<LinearLayout
android:animateLayoutChanges="true"
android:id="#+id/socketsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/socketsCollapse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:src="#drawable/ic_baseline_electrical_services_24" />
<TextView
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Sockets"
android:textSize="26sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/socketsFilters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
// SOMETHING
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</ScrollView>
Here is the java code:
package com.maxet24.chargely;
import android.animation.LayoutTransition;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.transition.AutoTransition;
import android.transition.TransitionManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MapFilterFragment extends Fragment implements View.OnClickListener {
public LinearLayout carsFilters, socketsFilters, carsLayout, socketsLayout, carsCollapse, socketsCollapse;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_map_filter, container, false);
// INIT
socketsLayout = v.findViewById(R.id.socketsLayout);
carsLayout = v.findViewById(R.id.carsLayout);
carsCollapse = v.findViewById(R.id.carsCollapse);
carsFilters = v.findViewById(R.id.carsFilters);
socketsCollapse = v.findViewById(R.id.socketsCollapse);
socketsFilters = v.findViewById(R.id.socketsFilters);
carsCollapse.setOnClickListener(this);
socketsCollapse.setOnClickListener(this);
carsLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
socketsLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
// INIT
return v;
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.carsCollapse:
Toast.makeText(getContext(), "Cars", Toast.LENGTH_SHORT).show();
toggleFilters(carsFilters, carsLayout);
case R.id.socketsCollapse:
Toast.makeText(getContext(), "Sockets", Toast.LENGTH_SHORT).show();
toggleFilters(socketsFilters, socketsLayout);
}
}
public void toggleFilters(LinearLayout filters, LinearLayout layout) {
TransitionManager.beginDelayedTransition(layout, new AutoTransition());
if (filters.getVisibility() == View.VISIBLE) {
filters.setVisibility(View.GONE);
} else{
filters.setVisibility(View.VISIBLE);
}
}
}
Full xml code (just in case):
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MapFilterFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
app:cardElevation="10dp"
app:contentPadding="20dp">
<LinearLayout
android:animateLayoutChanges="true"
android:id="#+id/carsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/carsCollapse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:src="#drawable/ic_baseline_electric_car_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Cars"
android:textSize="26sp"
android:textStyle="bold"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:id="#+id/carsFilters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView5"
android:layout_height="50dp"
android:layout_width="50dp"
app:srcCompat="#drawable/ch_type_1" />
<TextView
android:layout_marginLeft="30dp"
android:id="#+id/textView6"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Type 1"
android:layout_marginTop="4dp"
android:textSize="24sp" />
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="6dp"
tools:ignore="UseSwitchCompatOrMaterialXml"
android:layout_marginBottom="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="7dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView8"
android:layout_height="50dp"
android:layout_width="50dp"
app:srcCompat="#drawable/ch_type_2" />
<TextView
android:layout_marginLeft="30dp"
android:id="#+id/textView9"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Type 2"
android:layout_marginTop="4dp"
android:textSize="24sp" />
<Switch
android:id="#+id/switch2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="6dp"
tools:ignore="UseSwitchCompatOrMaterialXml"
android:layout_marginBottom="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="7dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView7"
android:layout_height="50dp"
android:layout_width="50dp"
app:srcCompat="#drawable/ch_type_3" />
<TextView
android:textAlignment="center"
android:layout_marginLeft="30dp"
android:id="#+id/textView8"
android:layout_width="110dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="CHAdeMO"
android:layout_marginTop="4dp"
android:textSize="24sp" />
<Switch
android:id="#+id/switch3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="6dp"
tools:ignore="UseSwitchCompatOrMaterialXml"
android:layout_marginBottom="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="7dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView9"
android:layout_height="50dp"
android:layout_width="50dp"
app:srcCompat="#drawable/ch_type_4" />
<TextView
android:layout_marginLeft="30dp"
android:id="#+id/textView10"
android:layout_width="110dp"
android:layout_height="70dp"
android:layout_weight="1"
android:text="CCS combo type 1"
android:layout_marginTop="4dp"
android:textSize="24sp" />
<Switch
android:id="#+id/switch4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="6dp"
tools:ignore="UseSwitchCompatOrMaterialXml"
android:layout_marginBottom="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="7dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView10"
android:layout_height="50dp"
android:layout_width="50dp"
app:srcCompat="#drawable/ch_type_5" />
<TextView
android:layout_marginLeft="30dp"
android:id="#+id/textView11"
android:layout_width="110dp"
android:layout_height="70dp"
android:layout_weight="1"
android:text="CCS combo type 2"
android:layout_marginTop="4dp"
android:textSize="24sp" />
<Switch
android:id="#+id/switch5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="6dp"
tools:ignore="UseSwitchCompatOrMaterialXml"
android:layout_marginBottom="10dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
app:cardElevation="10dp"
app:contentPadding="20dp">
<LinearLayout
android:animateLayoutChanges="true"
android:id="#+id/socketsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/socketsCollapse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:src="#drawable/ic_baseline_electrical_services_24" />
<TextView
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="Sockets"
android:textSize="26sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/socketsFilters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/example"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</ScrollView>
Thanks for any help!

Android - How do I expand the height of a view from bottom to top?

I'm trying to make a visualization of some data in Android using a vertical bar chart, but when I increase or decrease the height of a View programatically by clicking a button, it changes from top to bottom, as in the image below (default value is 300).
How do I change the height from bottom to top, ie keeping the base of the view fixed?
Expected result:
My code in Java:
public final class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
LinearLayout layoutXAxis = (LinearLayout)this.findViewById(R.id.layoutX);
LinearLayout layoutYAxis = (LinearLayout)this.findViewById(R.id.layoutY);
LinearLayout layoutZAxis = (LinearLayout)this.findViewById(R.id.layoutZ);
TextView txtXAxis = (TextView)layoutXAxis.findViewById(R.id.txtXAxis);
TextView txtYAxis = (TextView)layoutYAxis.findViewById(R.id.txtYAxis);
TextView txtZAxis = (TextView)layoutZAxis.findViewById(R.id.txtZAxis);
View graphXAxis = (View)layoutXAxis.findViewById(R.id.XAxis);
View graphYAxis = (View)layoutYAxis.findViewById(R.id.YAxis);
View graphZAxis = (View)layoutZAxis.findViewById(R.id.ZAxis);
LinearLayout layoutBtnAdd = (LinearLayout)this.findViewById(R.id.layAdd);
Button btnAddX = (Button)layoutBtnAdd.findViewById(R.id.btnXAdd);
Button btnAddY = (Button)layoutBtnAdd.findViewById(R.id.btnYAdd);
Button btnAddZ = (Button)layoutBtnAdd.findViewById(R.id.btnZAdd);
LinearLayout layoutBtnSub = (LinearLayout)this.findViewById(R.id.laySub);
Button btnSubX = (Button)layoutBtnSub.findViewById(R.id.btnXSub);
Button btnSubY = (Button)layoutBtnSub.findViewById(R.id.btnYSub);
Button btnSubZ = (Button)layoutBtnSub.findViewById(R.id.btnZSub);
txtXAxis.setText(String.valueOf(graphXAxis.getLayoutParams().height));
txtYAxis.setText(String.valueOf(graphYAxis.getLayoutParams().height));
txtZAxis.setText(String.valueOf(graphZAxis.getLayoutParams().height));
btnAddX.setOnClickListener((OnClickListener)(new OnClickListener() {
public final void onClick(View it) {
View graph = graphXAxis;
LayoutParams params = graph.getLayoutParams();
params.height += 10;
graph = graphXAxis;
graph.setLayoutParams(params);
TextView text = txtXAxis;
View graph = graphXAxis;
text.setText(String.valueOf(graph.getLayoutParams().height));
}
}));
... // onClickListener of the other buttons
}
My code in XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="#+id/layoutY">
<TextView
android:id="#+id/txtYAxis"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="Y AXIS"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#android:color/holo_blue_light"/>
...
<View android:id="#+id/YAxis"
android:layout_width="75dp"
android:layout_height="200dp"
android:background="#android:color/holo_blue_dark"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/layoutX"
android:layout_toLeftOf="#id/layoutY"
android:layout_toStartOf="#id/layoutY"
android:layout_marginRight="50dp"
android:layout_marginEnd="50dp">
<TextView
android:id="#+id/txtXAxis"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="X AXIS"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#android:color/holo_red_light"/>
...
<View android:id="#+id/XAxis"
android:layout_width="75dp"
android:layout_height="200dp"
android:background="#android:color/holo_red_dark"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/layoutZ"
android:layout_toRightOf="#id/layoutY"
android:layout_toEndOf="#id/layoutY"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp">
<TextView
android:id="#+id/txtZAxis"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="Z AXIS"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#android:color/holo_green_light"/>
...
<View android:id="#+id/ZAxis"
android:layout_width="75dp"
android:layout_height="200dp"
android:background="#android:color/holo_green_dark"/>
</LinearLayout>
...
</RelativeLayout>
You might consider constructing your layout like the following.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button_layout"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layoutY"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/txtYAxis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Y AXIS"
android:textColor="#android:color/holo_blue_light"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:id="#+id/YAxis"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#android:color/holo_blue_dark"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:id="#+id/layoutX"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|bottom"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/txtXAxis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="X AXIS"
android:textAlignment="center"
android:textColor="#android:color/holo_red_light"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:id="#+id/XAxis"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:id="#+id/layoutZ"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|bottom"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/txtZAxis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Z AXIS"
android:textAlignment="center"
android:textColor="#android:color/holo_green_light"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:id="#+id/ZAxis"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#android:color/holo_green_dark" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Here is the output.
Hope that helps!

For a view with rotation perform(click()) doesn't work in espresso ui test

I write an espresso UI test for my application, and for some views (in this case ImageButton) perform(click()) doesn't work and also no error is displayed.
this is the line that not worked:
try {
Thread.sleep(TIME_NORMAL_ELPASED);
} catch (InterruptedException e) {
e.printStackTrace();
}
onView(allOf(withId(R.id.toolbar_navigation_btn)
, isCompletelyDisplayed())).perform(click());
and this is my xml:
<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="match_parent"
android:layout_height="match_parent"
tools:context="activities.DepartFlight.fragments.AvailableFragment">
<android.support.v7.widget.Toolbar
android:id="#+id/available_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="#drawable/background_toolbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/toolbar_navigation_btn"
android:layout_width="#dimen/icon_toolbar"
android:layout_height="#dimen/icon_toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="#drawable/button_selector"
android:rotation="180"
android:src="#drawable/ic_back"
android:tint="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/text_toolbar_flight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:textColor="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/text_toolbar_flight"
android:layout_centerHorizontal="true"
android:textColor="#color/white"
android:textSize="#dimen/font_size" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<include
android:id="#+id/zero_filtered_items"
android:visibility="gone"
layout="#layout/zero_filterd_itesm_row" />
<com.faranegar.bookflight.customView.CustomRecyclerView
android:id="#+id/available_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/depart_flight_activity_footer"
android:layout_below="#id/available_toolbar"
android:background="#android:color/transparent"
android:visibility="gone"
/>
<com.tuyenmonkey.mkloader.MKLoader
android:id="#+id/progressBar"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_centerInParent="true"
android:visibility="gone"
app:mk_color="#color/colorPrimary"
app:mk_type="TwinFishesSpinner" />
<RelativeLayout
android:id="#+id/depart_flight_activity_footer"
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:visibility="visible">
<LinearLayout
android:id="#+id/view_sort"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/sort_icon"
android:tint="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/sortText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="#string/sort_text"
android:textColor="#color/white"
android:textSize="#dimen/text_less_normal" />
</LinearLayout>
<LinearLayout
android:id="#+id/view_filter"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="18dp"
android:layout_toRightOf="#id/view_sort"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_filter"
android:tint="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/filterText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="#string/filter_text"
android:textColor="#color/white"
android:textSize="#dimen/text_less_normal" />
</LinearLayout>
<RelativeLayout
android:id="#+id/next_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/back_day">
<Button
android:id="#+id/next_day_available_btn"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/button_selector"
android:textColor="#color/white"
android:textSize="#dimen/icon_btn" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/next_day_available_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/next_day_available_btn"
android:text="#string/next_day"
android:textColor="#color/white"
android:visibility="visible" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/back_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp">
<Button
android:id="#+id/prev_day_available_btn"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/prev_day_available_text"
android:background="#drawable/button_selector"
android:textColor="#color/white"
android:textSize="#dimen/icon_btn" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/prev_day_available_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="#string/back_day"
android:textColor="#color/white" />
</RelativeLayout>
</RelativeLayout>
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/not_available_flights"
android:textColor="#android:color/black"
android:textSize="16sp"
android:visibility="gone" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/ads_motto_captan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/progressBar"
android:layout_centerInParent="true"
android:padding="15dp"
android:text="#string/captan_ads_motto"
android:textColor="#color/colorPrimary"
android:textSize="16sp"
android:visibility="gone" />
<WebView
android:id="#+id/arzanBelitBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/depart_flight_activity_footer"
android:visibility="gone" />
<include
android:id="#+id/failedLayout"
layout="#layout/failed_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
/>
<include
android:id="#+id/saatraapProgressBarLayout"
layout="#layout/saatraap_brogressbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:visibility="gone" />
and a fragment shows the above XML.
what's wrong?
I think setRotation may have confused click() and coordinates calculation. If that's the case, you could either remove android:rotation then rotate the image physically, or try to create a custom click action:
public static ViewAction forceClick() {
return new ViewAction() {
#Override public Matcher<View> getConstraints() {
return allOf(isClickable(), isEnabled());
}
#Override public String getDescription() {
return "force click";
}
#Override public void perform(UiController uiController, View view) {
view.performClick();
uiController.loopMainThreadUntilIdle();
}
};
}
This action performs click on the view by invoking performClick() without finding its coordinates. But make sure the view has the click listener attached in the app:
onView(withId(R.id.toolbar_navigation_btn)).perform(forceClick());
If there's no error then it's safe to assume that the click was successful. Try enabling the "Show taps" Developer option to see exactly where the click occurs.

How to align ImageView and TextView in Custom ListView

I have created a Custom Adapter to show ImageView and TextView together in ListView. But the ImageView is showing on the top of TextView in every row of Listview. I have attached a screenshot of app below:
Custom Adapter Class:
public class CustomeAdapter extends BaseAdapter {
private Context context;
private ListView listView;
private ArrayList<PlayersModel> playersModelArrayList;
public CustomeAdapter(Context context, ArrayList<PlayersModel> playersModelArrayList) {
this.context = context;
this.playersModelArrayList = playersModelArrayList;
}
#Override
public int getViewTypeCount() {
return getCount();
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public int getCount() {
return playersModelArrayList.size();
}
#Override
public Object getItem(int position) {
return playersModelArrayList.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position,View convertView,ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.lv_item, null, true);
holder.icon = (TextView) convertView.findViewById(R.id.TextID);
holder.tvname = (TextView) convertView.findViewById(R.id.name);
holder.tvdescr = (TextView) convertView.findViewById(R.id.descr);
holder.tvlink = (TextView) convertView.findViewById(R.id.link);
holder.ImageIcon = (ImageView) convertView.findViewById(R.id.logoImageView);
convertView.setTag(holder);
}else {
holder = (ViewHolder)convertView.getTag();
}
holder.ImageIcon.setImageResource(playersModelArrayList.get(position).getImageId());
holder.icon.setText(playersModelArrayList.get(position).getICON());
holder.tvname.setText(playersModelArrayList.get(position).getName());
holder.tvdescr.setText(playersModelArrayList.get(position).getDescr());
holder.tvlink.setText(playersModelArrayList.get(position).getLink());
Glide.with(context)
.load("http://csalabs.in/wp-content/uploads/2017/10/CSA-Final-PNG-300x350.png")
.override(200,200)
.into(holder.ImageIcon);
Log.d("Icon URL",holder.icon.toString());
return convertView;
}
private class ViewHolder {
protected TextView icon, tvname, tvdescr, tvlink;
protected ImageView ImageIcon;
}
}
Layout File
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:onClick="buttonClickNew">
<ImageView
android:id="#+id/logoImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
tools:srcCompat="#tools:sample/avatars[0]" />
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#383838"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:textStyle="bold"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="Name" />
<TextView
android:id="#+id/descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#313131"
android:textSize="12sp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="Country" />
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#383838"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="#string/city"
android:visibility="gone"/>
<TextView
android:id="#+id/TextID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#313131"
android:textSize="12sp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorAccent"/>
</LinearLayout>
How to align ImageView on the left side of TextView? Thanks in advance.
BTW I am newbie in android and java.
Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/logoImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
tools:srcCompat="#tools:sample/avatars[0]" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="buttonClickNew"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#383838"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Country"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#313131"
android:textSize="12sp" />
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="city"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#383838"
android:visibility="visible" />
<TextView
android:id="#+id/TextID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#313131"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorAccent" />
</LinearLayout>
Use like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:onClick="buttonClickNew">
<ImageView
android:id="#+id/logoImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
tools:srcCompat="#tools:sample/avatars[0]" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:onClick="buttonClickNew">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#383838"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:textStyle="bold"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="Name" />
<TextView
android:id="#+id/descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#313131"
android:textSize="12sp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="Country" />
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#383838"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:text="#string/city"
android:visibility="gone"/>
<TextView
android:id="#+id/TextID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#313131"
android:textSize="12sp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"/>`enter code here`
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorAccent"/>
</LinearLayout>
Try to wrap Your text to separated LinearLayout with vertical orientation, and than put this LinearLayout with text on same level as ImageView inside another LinearLayout with orientation="horizontal"
But also, you should remember about render and measure performance.
You can read about this in https://android.jlelse.eu/constraint-layout-performance-870e5f238100
<LinearLayout
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_weight="1" // try to read about this parameter more
/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="4"
android:orientation="vertical">
<TextView ... />
<TextView ... />
<TextView ... />
</LinearLayout>
</LinearLayout>
Try to create two linear layouts with orientation vertical under parent linear layout which has the horizontal orientation.
Set the second linear layout's width to match_parent and the image layout should be a fixed width value.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonClickNew"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="#+id/logoImageView"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
tools:srcCompat="#tools:sample/avatars[0]" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#383838"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Country"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#313131"
android:textSize="12sp" />
<TextView
android:id="#+id/link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="City"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#383838"
android:visibility="gone" />
<TextView
android:id="#+id/TextID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#313131"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorAccent" />
</LinearLayout>
In order to simplify your xml, you should take a look to ConstraintLayout
To use it, make the import in your app gradle by adding implementation 'com.android.support.constraint:constraint-layout:1.1.3'
Then, refactor your xml as below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorAccent" android:id="#+id/view"
tools:layout_editor_absoluteX="0dp" app:layout_constraintTop_toBottomOf="#+id/logoImageView"
android:layout_marginTop="8dp"/>
<ImageView
android:layout_width="64dp"
android:layout_height="64dp" tools:srcCompat="#tools:sample/avatars"
android:id="#+id/logoImageView"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="#+id/name"
tools:text="Name"
android:textAppearance="#style/TextAppearance.AppCompat" android:textStyle="bold"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/descr" app:layout_constraintStart_toEndOf="#+id/logoImageView"
android:layout_marginStart="8dp"/>
<TextView
tools:text="Description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/descr" android:textColor="#313131"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="#+id/logoImageView"
app:layout_constraintStart_toEndOf="#+id/logoImageView" android:layout_marginStart="8dp"/>
</android.support.constraint.ConstraintLayout>

Shared element transition not working with second activity

Hi i am developing an app where i'm using shared element transition on textview however when i apply animation nothing happens and moreover text in other activity becomes invisible which is quite wierd i have given same transition name to both activities still i dont understand what the problem is please if someone can help me out here.
here is login activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.ct.listrtrial.activities.LoginActivity"
android:background="#color/colorPrimary">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:text="Login"
android:transitionName="#string/transition_name_signup"
android:id="#+id/text_login"
android:textColor="#color/White"
android:textSize="35sp" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="25dp"
android:id="#+id/login_card"
app:cardBackgroundColor="#color/White"
app:cardCornerRadius="20dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.ct.listrtrial.Custom.CustomEditText
android:layout_width="match_parent"
android:layout_height="80dp"
android:paddingLeft="10dp"
android:id="#+id/text_input_email"
>
<com.ct.listrtrial.Custom.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawableLeft="#drawable/message"
android:drawablePadding="10dp"
android:hint="Email id"
android:background="#android:color/transparent"/>
</com.ct.listrtrial.Custom.CustomEditText>
<View
android:id="#+id/card_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/light_black"
/>
<com.ct.listrtrial.Custom.CustomEditText
android:layout_width="match_parent"
android:layout_height="80dp"
android:paddingLeft="10dp"
android:id="#+id/text_input_password"
>
<com.ct.listrtrial.Custom.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawableLeft="#drawable/lock"
android:drawablePadding="10dp"
android:hint="Password"
android:background="#android:color/transparent"/>
</com.ct.listrtrial.Custom.CustomEditText>
</LinearLayout>
</android.support.v7.widget.CardView>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:text="Forgot Password?"
android:id="#+id/text_forgot_password"
android:textColor="#color/White"
android:textSize="18sp" />
</RelativeLayout>
<com.ct.listrtrial.widget.CustomButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#drawable/ripple_button_effect"
android:layout_marginBottom="16dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Login"
android:id="#+id/login_button"
android:textSize="20sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="OR CONNECT WITH"
android:textColor="#color/White"
android:textSize="15sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="50dp"
>
<com.ct.listrtrial.Custom.GoofleCustomImageView
android:id="#+id/facebook_image"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/facebook"
/>
<com.ct.listrtrial.Custom.GoofleCustomImageView
android:id="#+id/google_image"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/facebook_image"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/google_plus_1" />
</RelativeLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="250dp">
<ImageView
android:id="#+id/login_page_curve"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="gotoregister"
android:src="#drawable/login_page_curve" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:orientation="horizontal"
>
<com.ct.listrtrial.Custom.CustomTextViewMedium
android:id="#+id/or_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="130dp"
android:text="Or"
android:layout_marginTop="10dp"
android:textColor="#color/black"
android:textSize="17sp" />
<com.ct.listrtrial.Custom.CustomTextViewBold
android:id="#+id/register_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/or_text"
android:text="Register"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textColor="#color/black"
android:textSize="17sp" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
Login activity
public class LoginActivity extends AppCompatActivity {
CustomEditText text_input_email,text_input_password;
CustomButton login_button;
GoofleCustomImageView google_image,facebook_image;
ImageView login_page_curve;
CustomTextViewMedium or_text,text_forgot_password,text_login;
CustomTextViewBold register_text;
View myView;
boolean isUp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
initViews();
}
public void initViews(){
text_input_email = (CustomEditText)findViewById(R.id.text_input_email);
text_input_password = (CustomEditText)findViewById(R.id.text_input_password);
login_button = (CustomButton)findViewById(R.id.login_button);
google_image = (GoofleCustomImageView) findViewById(R.id.google_image);
facebook_image = (GoofleCustomImageView) findViewById(R.id.facebook_image);
login_page_curve = (ImageView)findViewById(R.id.login_page_curve);
or_text = (CustomTextViewMedium)findViewById(R.id.or_text);
text_forgot_password = (CustomTextViewMedium)findViewById(R.id.text_forgot_password);
register_text = (CustomTextViewBold)findViewById(R.id.register_text);
text_login = (CustomTextViewMedium)findViewById(R.id.text_login);
}
public void gotoregister(View view) {
Intent intent = new Intent(LoginActivity.this,RegisterActivity.class);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation
(LoginActivity.this,login_page_curve,
getResources().getString(R.string.transition_name_signup));
startActivity(intent,options.toBundle());
overridePendingTransition(R.anim.bottom_up,R.anim.bottom_down);
finish();
}
}

Categories