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();
}
}
Related
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!
Although I used the "replace" method on the piece, the second part of the piece runs on the first part It should be noted that my code is only in (main activity) and there is no code in the second fragment section (I mean the "about" fragment here) (there is a fragment class by default) so I sent it I did not
I also put a background in the xml file, but the following part works although it is not clear
Please guide me on this
Thanks
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
.
.
.
LinearLayout lnrRecyclerNoConnection, li_home, li_share, li_about, li_logout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
replace(new HomeFragment());
...
}
.
.
.
#Override
public void onClick(View view) {
int id = view.getId();
if (id == R.id.ivMenu) {
mDrawer.openMenu(true);
} else if (id == R.id.li_home) {
replace(new HomeFragment(), "Home");
mDrawer.closeMenu(true);
} else if (id == R.id.li_about) {
replace(new AboutFragment(), "About");
mDrawer.closeMenu(true);
} else if (id == R.id.li_share) {
Toast.makeText(this, "share", Toast.LENGTH_SHORT).show();
mDrawer.closeMenu(true);
} else if (id == R.id.li_logout) {
Toast.makeText(this, "exited", Toast.LENGTH_SHORT).show();
finish();
System.exit(0);
}
}
private void replace(Fragment fragment, String string) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fl_main, fragment);
fragmentTransaction.addToBackStack(string);
fragmentTransaction.commit();
}
private void replace(Fragment fragment) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fl_main, fragment);
fragmentTransaction.commit();
}
}
This is also the XML code section
I put "Replace" in the main activity section
<?xml version="1.0" encoding="utf-8"?>
<com.mxn.soul.flowingdrawer_core.FlowingDrawer xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
app:edPosition="2"
app:edMenuSize="260dp"
app:edMenuBackground="#F1F1F1">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_marginEnd="0dp"
android:animateLayoutChanges="true"
android:background="#color/colorBackground">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/mainAppBar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/mainCollapsingToolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="start|top"
app:expandedTitleMarginTop="56dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:id="#+id/mainHeader"
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="#+id/imgChannelCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/cover_placeholder" />
<TextView
android:id="#+id/txtChannelFollower_cnt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:fontFamily="#font/yekan"
android:gravity="center_horizontal"
android:textColor="#color/colorPrimary"
android:textSize="16sp"
tools:ignore="NotSibling" />
<TextView
android:id="#+id/txtVideo_cnt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/txtChannelFollower_cnt"
android:layout_alignEnd="#+id/txtChannelFollower_cnt"
android:layout_alignParentBottom="true"
android:layout_marginBottom="16dp"
android:fontFamily="#font/yekan"
android:gravity="center_horizontal"
android:textColor="#color/colorPrimary"
android:textSize="16sp" />
</RelativeLayout>
<androidx.appcompat.widget.Toolbar
android:id="#+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:paddingStart="16dp"
android:paddingEnd="16dp"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<ImageView
android:id="#+id/imgShowChannelDescription"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="start"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:src="#drawable/person_outline_24" />
<ImageView
android:id="#+id/ivMenu"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:src="#drawable/menu_open_24" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:id="#+id/lnrRecyclerNoConnection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<pl.droidsonroids.gif.GifImageView
android:id="#+id/gifVideoLoading"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:src="#drawable/no_connection"
android:tint="#color/colorPrimary" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/yekan"
android:gravity="center_horizontal"
android:text="#string/noConnection" />
<Button
android:id="#+id/btnRecyclerTryConnection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:background="#drawable/btn_selector"
android:fontFamily="#font/yekan"
android:text="refresh"
android:textColor="#color/colorWhiteTextColor"
android:textStyle="bold" />
</LinearLayout>
<com.facebook.shimmer.ShimmerFrameLayout
android:id="#+id/shimmerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/shimmer_screen" />
<include layout="#layout/shimmer_screen" />
<include layout="#layout/shimmer_screen" />
<include layout="#layout/shimmer_screen" />
</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/mainRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/CircleImageChannelProfile"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentEnd="true"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:src="#drawable/image_placeholder"
app:civ_border_color="#color/colorPrimary"
app:civ_border_width="1dp"
app:layout_anchor="#id/mainAppBar"
app:layout_anchorGravity="center_vertical|center_horizontal" />
<!--<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/CircleImageChannelProfile"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:src="#drawable/image_placeholder"
app:civ_border_color="#color/colorPrimary"
app:civ_border_width="0.5dp"
app:layout_anchor="#id/mainAppBar"
app:layout_anchorGravity="bottom|end" />-->
<!--content-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/fl_main"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<!--menu-->
<com.mxn.soul.flowingdrawer_core.FlowingMenuLayout
android:id="#+id/menulayout"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/id_container_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/header">
<ImageView
android:id="#+id/imgChannelCoverDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/bg_card_video_main"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorPrimary">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/CircleImageChannelProfileDrawer"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="50dp"
android:src="#drawable/image_placeholder"
app:civ_border_color="#color/colorPrimary"
app:layout_anchor="#id/mainAppBar"
app:layout_anchorGravity="center_vertical|center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="title"
android:textSize="28sp"
android:fontFamily="#font/yekan"
android:textColor="#color/cardview_dark_background"
android:gravity="center_horizontal|center_vertical"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/li_home"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layoutDirection="rtl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="48dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/home_24"
android:padding="4dp"
app:tint="#color/cardview_dark_background"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="home"
android:textColor="#color/cardview_dark_background"
android:fontFamily="#font/yekan"
android:textSize="16sp"
android:padding="4dp"/>
</LinearLayout>
<!--<LinearLayout
android:id="#+id/li_about"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layoutDirection="rtl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/li_share"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="24dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/person_outline_24"
android:padding="4dp"
app:tint="#color/cardview_dark_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="about"
android:textColor="#color/cardview_dark_background"
android:fontFamily="#font/yekan"
android:textSize="16sp"
android:padding="4dp"/>
</LinearLayout>-->
<LinearLayout
android:id="#+id/li_share"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layoutDirection="rtl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/li_home"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="24dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/share_24"
android:padding="4dp"
app:tint="#color/cardview_dark_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="اشتراک گذاری"
android:textColor="#color/cardview_dark_background"
android:fontFamily="#font/yekan"
android:textSize="16sp"
android:padding="4dp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/li_logout"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layoutDirection="rtl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/li_share"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="24dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_power_settings_new_24"
android:padding="4dp"
app:tint="#color/cardview_dark_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="exit"
android:textColor="#color/cardview_dark_background"
android:fontFamily="#font/yekan"
android:textSize="16sp"
android:padding="4dp"/>
</LinearLayout>
</RelativeLayout>
</com.mxn.soul.flowingdrawer_core.FlowingMenuLayout>
</com.mxn.soul.flowingdrawer_core.FlowingDrawer>
This question already has an answer here:
Cardview Click is not opening Activty
(1 answer)
Closed 3 years ago.
My problems :
My apps doesn't have error.
When I click at the button, my page isn't display.
It can exist when I click at the certain place not at the button.
I already do refer by youtube, but myself cannot resolve this problem.
This is my java file :
dashboard.java
package com.example.whatisthat;
import androidx.cardview.widget.CardView;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class Dashboard extends Activity implements View.OnClickListener
{
private CardView LoginBtn, CaptureBtn, AboutBtn, FeedbackBtn, IgBtn, HelpBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
//DEFINE CARDS
//ADD CLICK LISTENER TO THE CARDS
LoginBtn = findViewById(R.id.Login);
LoginBtn.setOnClickListener(this);
CaptureBtn = findViewById(R.id.Capture);
CaptureBtn.setOnClickListener(this);
AboutBtn = findViewById(R.id.About);
AboutBtn.setOnClickListener(this);
FeedbackBtn = findViewById(R.id.Feedback);
FeedbackBtn.setOnClickListener(this);
IgBtn = findViewById(R.id.Ig);
IgBtn.setOnClickListener(this);
HelpBtn = findViewById(R.id.Help);
HelpBtn.setOnClickListener(this);
}
#Override
public void onClick(View view)
{
Intent i;
switch (view.getId())
{
case R.id.Login : i = new Intent(this,Login1.class);
startActivity(i);
break;
case R.id.Capture : i = new Intent(this, Capture.class);
startActivity(i);
break;
case R.id.About : i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.Feedback : i = new Intent(this, Feedback.class);
startActivity(i);
break;
case R.id.Ig : i = new Intent(this, Instagram.class);
startActivity(i);
break;
case R.id.Help : i = new Intent(this, Help.class);
startActivity(i);
break;
default:break;
}
}
}
This is my xml file :
activity_dashboard.xml
<?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="match_parent"
android:layout_height="match_parent"
tools:context=".Dashboard">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="230dp"
android:orientation="vertical"
android:gravity="center"
android:background="#6A287E">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/iconfyp"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DASHBOARD"
android:textColor="#color/colorAccent"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="18sp"
android:layout_marginTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="215dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:foreground="?android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true”
android:id="#+id/Login"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView1"
android:layout_height="50dp"
android:src="#drawable/people"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
android:textSize="16sp"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:foreground="?android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true”
android:id="#+id/Capture"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView2"
android:layout_height="50dp"
android:src="#drawable/cameraa"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAPTURE"
android:textSize="16sp"
android:layout_below="#+id/imageView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:foreground="?android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true”
android:id="#+id/About"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView3"
android:layout_height="50dp"
android:src="#drawable/aboutt"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABOUT"
android:textSize="16sp"
android:layout_below="#+id/imageView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:foreground="?android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true”
android:id="#+id/Feedback"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView4"
android:layout_height="50dp"
android:src="#drawable/feedback"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FEEDBACK "
android:textSize="16sp"
android:layout_below="#+id/imageView4"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:foreground="?android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true”
android:id="#+id/Ig"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView5"
android:layout_height="50dp"
android:src="#drawable/instagram"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INSTAGRAM"
android:textSize="16sp"
android:layout_below="#+id/imageView5"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:foreground="?android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true”
android:id="#+id/Help"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView6"
android:layout_height="50dp"
android:src="#drawable/help"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELP"
android:textSize="16sp"
android:layout_below="#+id/imageView6"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
add android:clickable="true" , android:focusable="true" and android:foreground="?android:attr/selectableItemBackground"
<androidx.cardview.widget.CardView
android:foreground="?android:attr/selectableItemBackground"
android:focusable="true
android:clickable="true"
android:id="#+id/Feedback"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
// your code
</androidx.cardview.widget.CardView>
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!
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>