I have an error the first time that my fragment with cardviews is shown, they become much larger and only fit 2 on the screen, that is, only one row of two columns when they should show 6, first I saw that it happened and now I I realized that when re-entering the fragment since this is the one by default, if I re-enter if it is shown as it should, this fragment is inside a navigation draw
I attach a capture of how it looks at the beginning, when entering the application:
enter image description here
And in the next one it looks like this when I re-enter the fragment or I refresh it:
enter image description here
Here I leave you as seen in the android designer:
enter image description here
And finally the xml of the layout:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".NumericalMethods.NonlinearEquations.NonlinearEquationsFragment"
android:background="#drawable/bg_ne"
>
<TextView
android:id="#+id/title_nonlinear_ecuations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Resolucion de \nEcuaciones No lineales "
android:textColor="#color/white"
android:textSize="30dp"
android:textAlignment="center"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
/>
<GridLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="3"
android:columnCount="2"
android:layout_below="#id/title_nonlinear_ecuations">
<androidx.cardview.widget.CardView
android:id="#+id/card_fp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_pf" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Punto Fijo"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/car_nr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_nr"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Newton Raphson"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_sec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_sec"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="La secante"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/car_fake_pos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_pos_falsa"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Posicion Falsa"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_bisec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_bisection"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Biseccion"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card_muller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_muller"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Muller"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20dp"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</RelativeLayout>
And emphasize that it only happens when the application starts, and when I take a step back, when I say this I mean the button this:
enter image description here
My Activity:
class MainActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)
val fab: FloatingActionButton = findViewById(R.id.fab)
fab.setOnClickListener { view ->
Snackbar.make(view, "Aplicacion Realizada por E.R.", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
val navView: NavigationView = findViewById(R.id.nav_view)
val navController = findNavController(R.id.nav_host_fragment)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
appBarConfiguration = AppBarConfiguration(setOf(
R.id.nav_ne, R.id.nav_sne, R.id.nav_fai, R.id.nav_id, R.id.nav_edo, R.id.nav_edp), drawerLayout)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
return true
}
override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.nav_host_fragment)
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
}
}
My mobile_navigartion.xml:
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="#+id/mobile_navigation"
app:startDestination="#+id/nav_ne">
<fragment
android:id="#+id/nav_ne"
android:name="com.yr.mnlite.NumericalMethods.NonlinearEquations.NonlinearEquationsFragment"
android:label="#string/menu_ne"
tools:layout="#layout/fragment_nonlinear_equations" />
<fragment
android:id="#+id/nav_sne"
android:name="com.yr.mnlite.NumericalMethods.SistemNonlinearEquations.SistemNonlinearEquationsFragment"
android:label="#string/menu_sne"
tools:layout="#layout/fragment_sistem_nonlinear_equations" />
<fragment
android:id="#+id/nav_fai"
android:name="com.yr.mnlite.NumericalMethods.FunctionalApproximationAndInterpolation.FunctionalApproximationAndInterpolationFragment"
android:label="#string/menu_fai"
tools:layout="#layout/fragment_functional_approximation_and_interpolation" />
<fragment
android:id="#+id/nav_id"
android:name="com.yr.mnlite.NumericalMethods.IntegrationDifferentiation.IntegrationDifferentiationFragment"
android:label="#string/menu_id"
tools:layout="#layout/fragment_integration_differentiation" />
<fragment
android:id="#+id/nav_edo"
android:name="com.yr.mnlite.NumericalMethods.OrdinaryDifferentialEquations.OrdinaryDifferentialEquationsFragment"
android:label="#string/menu_edo"
tools:layout="#layout/fragment_ordinary_differential_equations" />
<fragment
android:id="#+id/nav_edp"
android:name="com.yr.mnlite.NumericalMethods.PartialDifferentialEquations.PartialDifferentialEquationsFragment"
android:label="#string/menu_edp"
tools:layout="#layout/fragment_partial_differential_equations" />
</navigation>
Thank you all very much I am new to android.
Can you try this?
<androidx.cardview.widget.CardView
android:id="#+id/card_fp"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
Related
I'm sorry for the confusion for the title but this is what happens
This is what the app looks like and it works fine.
HOWEVER...
When the app is launched everytime it shows this.
For some weird reason the card view stretches. This only happens everytime you open the app. It goes back to normal when you tap on assessment then go back.
I don't know what to do because my xml codes is all working as intended on the first photo and I don't know what causes this problem.
CODE:
<TextView
android:id="#+id/title_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="12dp"
android:text=" "
android:textColor="#fff"
android:fontFamily="#font/ness"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="#+id/title_view2"
android:layout_width="294dp"
android:layout_height="58dp"
android:layout_below="#+id/title_view"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="65dp"
android:layout_marginTop="45dp"
android:layout_marginEnd="52dp"
android:layout_marginBottom="112dp"
android:fontFamily="#font/ness"
android:text="What do you want to do today?"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/title_view"
android:layout_margin="100dp"
android:columnCount="2"
android:rowCount="3">
<androidx.cardview.widget.CardView
android:id="#+id/assess_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/asses" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Assessment"
android:textAlignment="center"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/profile_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/profile" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile"
android:textAlignment="center"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
Do you need grid layout in this ui? And your android:columnCount="2" and android:rowCount="3" it's can be reason. Maybe you should use constraintlayout.
UPDATED
Try code below, maybe it can solve your problem.
Also I have seen you used RelativeLayout, for now day it's deprecated and google recommend to use constraintlayout.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title_view2"
android:layout_width="294dp"
android:layout_height="58dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:fontFamily="#font/ness"
android:text="What do you want to do today?"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.cardview.widget.CardView
android:id="#+id/assess_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="#+id/title_view2"
app:layout_constraintStart_toStartOf="#+id/title_view2"
app:layout_constraintTop_toBottomOf="#+id/title_view2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/asses" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Assessment"
android:textAlignment="center"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/profile_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_marginTop="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="#+id/assess_menu"
app:layout_constraintStart_toStartOf="#+id/assess_menu"
app:layout_constraintTop_toBottomOf="#+id/assess_menu">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/profile" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile"
android:textAlignment="center"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Let me tell you first, this is not duplicate question. I have tried every solution from stackoverflow. but nothing work for me.
in my Application, I implementing two gridlayout. first one scroll horizontal and second one scroll vertical. but the problem is when i add scrollview to the second Gridview it hide top content that is my texrview and imagview.
I don't understand. what I am doing wrong.
This is code:
<FrameLayout 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=".ui.home.HomeFragment">
<LinearLayout
android:orientation="vertical"
android:weightSum="10"
android:paddingTop="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textGrid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:fontFamily="#font/quicksand_bold"
android:paddingStart="20dp"
android:text="Welcome"
android:textColor="#141D50"
android:textSize="34sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/search"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="150dp"
android:src="#android:drawable/ic_search_category_default"
app:tint="#141D50"
tools:ignore="UnknownId" />
</LinearLayout>
</RelativeLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="50dp">
<GridLayout
android:id="#+id/mainGrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="8"
android:alignmentMode="alignMargins"
android:columnOrderPreserved="false"
android:numColumns="6"
android:padding="8dp"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="horizontal">
<androidx.cardview.widget.CardView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardBackgroundColor="#color/colorPrimaryDark"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/street"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/dress"
app:tint="#android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#+id/electricity"
android:layout_gravity="center"
android:fontFamily="#font/quicksand_bold"
android:paddingTop="10dp"
android:text="Dress"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardBackgroundColor="#color/colorPrimaryDark"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/other"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/bags"
app:tint="#android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#+id/electricity"
android:layout_gravity="center"
android:fontFamily="#font/quicksand_bold"
android:paddingTop="5dp"
android:text="Bags"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardBackgroundColor="#color/colorPrimaryDark"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/other1"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/toys"
app:tint="#android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#+id/electricity"
android:layout_gravity="center"
android:fontFamily="#font/quicksand_bold"
android:paddingTop="5dp"
android:text="Toys"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</LinearLayout>
</HorizontalScrollView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_weight="1"
android:fillViewport="true"
android:focusableInTouchMode="true"
app:layout_constrainedHeight="true">
<GridLayout
android:id="#+id/mainGrid1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:alignmentMode="alignMargins"
android:columnCount="2"
android:columnOrderPreserved="false"
android:padding="14dp">
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/electricity1"
android:layout_width="wrap_content"
android:layout_height="104dp"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/electricity"
android:layout_gravity="center"
android:text="water supply"
android:textAlignment="center"
android:textColor="#141D50"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/water1"
android:layout_width="wrap_content"
android:layout_height="104dp"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="water supply"
android:textAlignment="center"
android:textColor="#141D50"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/clean1"
android:layout_width="wrap_content"
android:layout_height="104dp"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Cleanliness"
android:textAlignment="center"
android:textColor="#141D50"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<!-- Column 2 -->
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/street1"
android:layout_width="wrap_content"
android:layout_height="104dp"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Street"
android:textAlignment="center"
android:textColor="#141D50"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/m"
android:layout_width="wrap_content"
android:layout_height="104dp"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Other"
android:textAlignment="center"
android:textColor="#141D50"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/m1"
android:layout_width="wrap_content"
android:layout_height="104dp"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Other"
android:textAlignment="center"
android:textColor="#141D50"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</ScrollView>
</LinearLayout>
</FrameLayout>
It happens, because you written android:layout_weight="1" in RelativeLayout.
First of all, remove android:layout_weight="1" from your RelativeLayout.
Secondly, set RelativeLayout height as a wrap_content.
Before:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
After:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
I want to link my image to a new activity, I tried multiple of codes and solution online but I am having an error.
public class MainActivity extends AppCompatActivity {
ImageButton myImageButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myImageButton = (ImageButton) findViewById(R.id.APZ);
myImageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intentLoadActivity = new Intent(MainActivity.this,APZ.class);
startActivity(intentLoadActivity);
}
});
}
}
My problem is the ID I have set in the image is having an error, see the screenshot below:
https://imgur.com/t5KkTGl
Activity_main.XML code:
<?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=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Astoria Hotels and Resorts"
android:textStyle="bold"
android:textSize="25sp"
/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="3"
android:columnCount="2"
>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
android:layout_marginTop="25pt"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:id="#+id/APZ"
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/astoria_plaza___project_logo___primary_lockup__small_" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Plaza"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
android:layout_marginTop="25pt"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:id="#+id/imageView4"
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/agb_transparent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Greenbelt"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/astoria_current_transparent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Current"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/ab1_transparent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Boracay"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="123dp"
android:layout_height="140dp"
app:srcCompat="#drawable/abh___transparent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Astoria Bohol"
android:textStyle="bold"
android:textAlignment="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</RelativeLayout>
Help please thanks!
You are using ImageButton in java. If you want to use it replace ImageView with ImageButton in your layout.xml
I have this xml. The problem is the things are side by side and I'd like they this way:
CircleImageView - shareName // line break
shareTextViewPublisher // line break
shareimageViewHero // line break
but they are all in the same line. how to do this?
<LinearLayout
android:id="#+id/shareTable"
android:layout_width="match_parent"
android:layout_margin="50dp"
android:padding="10dp"
android:visibility="gone"
android:background="#drawable/border"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:id="#+id/sharePic"
android:paddingBottom="10dp"
android:paddingLeft="1dp" />
<TextView
android:id="#+id/shareName"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:paddingLeft="1dp"
android:layout_weight="1"
/>
<TextView
android:id="#+id/shareTextViewPublisher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:padding="0dp"
android:id="#+id/shareimageViewHero"
android:adjustViewBounds="true"/>
</LinearLayout>
If you want to do this using LinearLayout you should put your CircleImageView and shareName in additional horizontal LinearLayout. The structure of the XML should like this:
<LinearLayout
android:id="#+id/shareTable"
android:layout_width="match_parent"
android:layout_margin="50dp"
android:padding="10dp"
android:background="#drawable/border"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:id="#+id/sharePic"
android:paddingBottom="10dp"
android:paddingLeft="1dp" />
<TextView
android:id="#+id/shareName"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:paddingLeft="1dp"
android:layout_weight="1"
/>
</LinearLayout>
<TextView
android:id="#+id/shareTextViewPublisher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:padding="0dp"
android:id="#+id/shareimageViewHero"
android:adjustViewBounds="true"/>
</LinearLayout>
I'm implementing a Recycler View in Android to create a list, but for some reason I see a space in between two elements, and I'm not able to pinpoint the error location. As to why is this happening, my guess is on the row element XML.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview1="http://schemas.android.com/apk/res-auto"
android:id="#+id/row_top_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/pos_cv"
android:layout_width="match_parent"
android:layout_height="72dp"
android:clickable="true"
cardview1:cardCornerRadius="6dp"
cardview1:cardElevation="4dp"
cardview1:cardMaxElevation="6dp">
<TextView
android:id="#+id/manager1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="15dp"
android:text="Store Manager/Branch"
android:textSize="14sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal">
<TextView
android:id="#+id/retail"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:text="Abc Retail"
android:textSize="10sp" />
<View
android:layout_width="170dp"
android:layout_height="match_parent" />
<TextView
android:id="#+id/amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="25,000"
android:textColor="#color/colorDarkPink"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/address"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="50dp"
android:text="Abc Retail"
android:textSize="10sp" />
</android.support.v7.widget.CardView>
RecyclerView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/list_view_header_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:weightSum="5"
android:background="#color/colorDarkPink"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top 3 Performers"
android:textStyle="bold"
android:textColor="#color/colorPrimaryLight"
android:layout_weight="3"
android:textSize="16sp"
android:lines="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sales"
android:textStyle="bold"
android:textColor="#color/colorPrimaryLight"
android:layout_weight="2"
android:textSize="16sp"
android:lines="1"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/performer_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#color/colorTransparent"
android:layout_marginTop="16dp"
android:dividerHeight="4dp"
/>
It is because of recycler view height. Try to change recyclerview height to wrap_content.And in cardview layout in linear-layout use height wrap_content.
try this code for your cardview:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview1="http://schemas.android.com/apk/res-auto"
android:id="#+id/row_top_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/pos_cv"
android:layout_width="match_parent"
android:layout_height="72dp"
android:clickable="true"
android:layout_marginBottom="10dp"
cardview1:cardCornerRadius="6dp"
cardview1:cardElevation="4dp"
cardview1:cardMaxElevation="6dp">
<TextView
android:id="#+id/manager1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="15dp"
android:text="Store Manager/Branch"
android:textSize="14sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal">
<TextView
android:id="#+id/retail"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:text="Abc Retail"
android:textSize="10sp" />
<View
android:layout_width="170dp"
android:layout_height="match_parent" />
<TextView
android:id="#+id/amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="25,000"
android:textColor="#color/colorDarkPink"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/address"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="50dp"
android:text="Abc Retail"
android:textSize="10sp" />
</android.support.v7.widget.CardView>
</LinearLayout>
Try to decrease your values
android:layout_height="50dp"
if it will not work try to decrease values in other views