Image Button to new Activity: Android Studio - android-studio

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

Related

App shows a different activity layout when launched for the first time

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>

Android scrollview hiding top widget in layout

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"
>

Error first time fragment is displayed with cardview

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"
>

xml change side by side elements

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 want to show enable a button on first click and when other button is clicked, then the previously clicked one should be inactive

I had set images in drawable and tried to set them by using onClickListeners and uing View.VISIBLE and View.GONE but once the button is clicked it becomes active forever whereas i want the previously clicked button to be disabled or inactive when new one is clicked. Please help me out anyone?
XML code:
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="#+id/toolbartitle"
android:layout_toLeftOf="#+id/toolbartitle"
android:layout_toStartOf="#+id/toolbartitle"
android:id="#+id/linearLayout3"
android:orientation="horizontal"></LinearLayout>
<HorizontalScrollView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="#+id/horizontalScrollView"
android:fillViewport="false"
android:background="#ffffff"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:scrollbars="none"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:contextClickable="false"
android:focusable="false"
android:layout_marginTop="80dp">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="#ffffff"
android:layout_alignTop="#+id/horizontalScrollView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="#+id/miniscrollRelative"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/home"
android:id="#+id/textViewab"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"
android:textSize="8dp"/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/player"
android:id="#+id/textViewba"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="70dp"
android:layout_marginTop="50dp"
android:textSize="8dp" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/Your_play.."
android:id="#+id/textViewca"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="130dp"
android:layout_marginTop="50dp"
android:textSize="8dp" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/downloads"
android:id="#+id/textViewda"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="200dp"
android:layout_marginTop="50dp"
android:textSize="8dp" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/streaming"
android:id="#+id/textViewea"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="270dp"
android:layout_marginTop="50dp"
android:textSize="8dp" />
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonhomea"
android:src="#drawable/homenew"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_alignBottom="#+id/imageButtonda"
android:layout_toRightOf="#+id/imageButtonaab"
android:layout_toEndOf="#+id/imageButtonaab" />
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonaa"
android:src="#drawable/player"
android:layout_marginLeft="60dp"
android:background="#ffffff"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonaab"
android:src="#drawable/player_active"
android:layout_marginLeft="60dp"
android:background="#ffffff"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonba"
android:src="#drawable/mydownload"
android:layout_marginLeft="195dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonbab"
android:src="#drawable/download_active"
android:layout_marginLeft="195dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonca"
android:src="#drawable/playlist"
android:layout_marginLeft="130dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"
/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtoncab"
android:src="#drawable/playlist_active"
android:layout_marginLeft="130dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonda"
android:src="#drawable/streaming"
android:layout_marginLeft="265dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtondab"
android:src="#drawable/streaming_active"
android:layout_marginLeft="265dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginTop="10dp"
android:visibility="gone"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_toRightOf="#+id/miniscrollRelative"
android:layout_marginLeft="30dp">
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/send_wishes"
android:id="#+id/textViewfa"
android:textSize="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="50dp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/hit_parade"
android:id="#+id/textViewga"
android:textSize="8dp"
android:layout_marginLeft="78dp"
android:layout_marginTop="50dp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/uzbek_instr"
android:id="#+id/textViewha"
android:textSize="8dp"
android:layout_marginLeft="145dp"
android:layout_marginTop="50dp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/your_news"
android:id="#+id/textViewia"
android:textSize="8dp"
android:layout_marginLeft="220dp"
android:layout_marginTop="50dp"
/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/extras"
android:id="#+id/textViewja"
android:textSize="8dp"
android:layout_marginLeft="300dp"
android:layout_marginTop="50dp"
android:layout_marginRight="5dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonea"
android:src="#drawable/wishes"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"
android:layout_alignTop="#+id/imageButtonfa"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtoneab"
android:src="#drawable/hitparadea"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonfa"
android:src="#drawable/hitparade"
android:layout_marginLeft="80dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonfab"
android:src="#drawable/hitparade1"
android:layout_marginLeft="80dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonga"
android:src="#drawable/instrument"
android:layout_marginLeft="150dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtongab"
android:src="#drawable/instrument_active"
android:layout_marginLeft="150dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonha"
android:src="#drawable/news"
android:layout_marginLeft="220dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonhab"
android:src="#drawable/news_active"
android:layout_marginLeft="220dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:background="#ffffff"
android:visibility="gone"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtonia"
android:src="#drawable/extras"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginRight="5dp"/>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/imageButtoniab"
android:src="#drawable/extras_active"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp"
android:layout_marginRight="5dp"
android:visibility="gone"/>
</RelativeLayout>
</RelativeLayout>
</HorizontalScrollView>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/right"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="#+id/horizontalScrollView"
android:layout_alignTop="#+id/toolBar"
android:id="#+id/right" />
<ImageButton
android:id="#+id/left"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/left"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="#+id/horizontalScrollView"
android:layout_alignTop="#+id/toolBar" />
<FrameLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:name="android.app.ListFragment"
android:id="#+id/fragment"
android:background="#ffffff"
android:layout_below="#+id/horizontalScrollView"
android:layout_alignRight="#+id/toolBar"
android:layout_alignEnd="#+id/toolBar">
<FrameLayout
android:background="#f2434242"
android:layout_width="match_parent"
android:layout_height="202dp"
android:layout_gravity="left|bottom">
<RelativeLayout
android:background="#f2696868"
android:layout_width="match_parent"
android:layout_height="131dp"
android:id="#+id/relativeLayoutad"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal|bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AD"
android:id="#+id/textView7"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center_horizontal|top">
<ImageView
android:layout_width="49dp"
android:layout_height="49dp"
android:background="#drawable/playerbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/imageView3"
android:layout_alignParentTop="true"
android:layout_above="#+id/seekBar2" />
<ImageButton
android:background="#drawable/minipause"
android:layout_width="35dp"
android:layout_height="35dp"
android:id="#+id/button2"
android:layout_gravity="center_horizontal|top"
android:layout_marginRight="27dp"
android:layout_marginEnd="27dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/button4"
android:layout_toStartOf="#+id/button4" />
<ImageButton
android:background="#drawable/minisound"
android:layout_width="35dp"
android:layout_height="35dp"
android:id="#+id/button4"
android:layout_gravity="center_horizontal|top"
android:layout_alignTop="#+id/button2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<SeekBar
android:layout_width="match_parent"
android:layout_height="2dp"
android:id="#+id/seekBar2"
android:layout_weight="0.87"
android:progress="100"
android:progressDrawable="#drawable/seekbar3"
android:max="200"
android:thumb="#null"
android:maxHeight="3dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_below="#+id/button2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio"
android:textColor="#ffffff"
android:id="#+id/textView5"
android:layout_alignTop="#+id/imageView3"
android:layout_toRightOf="#+id/imageView3"
android:layout_toEndOf="#+id/imageView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UZ"
android:textColor="#ffffff"
android:id="#+id/textView6"
android:layout_alignLeft="#+id/textView5"
android:layout_alignStart="#+id/textView5"
android:layout_alignRight="#+id/textView5"
android:layout_alignEnd="#+id/textView5"
android:layout_below="#+id/textView5" />
</RelativeLayout>
</FrameLayout>
</FrameLayout>
<TextView
android:layout_width="match_parent" android:layout_height="50dp"
android:text="player"
android:textSize="22sp"
android:gravity = "center"
android:id="#+id/toolbartitle"
android:layout_above="#+id/toolBar"
android:layout_alignLeft="#+id/toolBar"
android:layout_alignStart="#+id/toolBar" />
</RelativeLayout>
And here is the java code:
public class FragmentForScrollBar extends Fragment {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragmentforscrollbar,null);
MyPlayer playerFragment = new MyPlayer();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, playerFragment, null);
fragmentTransaction.commit();
hsv = (HorizontalScrollView) view.findViewById(R.id.horizontalScrollView);
t = (TextView)view.findViewById(R.id.toolbartitle);
home =(ImageButton)view.findViewById(R.id.imageButtonhomea);
player =(ImageButton)view.findViewById(R.id.imageButtonaa);
playlist =(ImageButton)view.findViewById(R.id.imageButtonca);
download =(ImageButton)view.findViewById(R.id.imageButtonba);
stream =(ImageButton)view.findViewById(R.id.imageButtonda);
wish =(ImageButton)view.findViewById(R.id.imageButtonea);
hit =(ImageButton)view.findViewById(R.id.imageButtonfa);
instrument =(ImageButton)view.findViewById(R.id.imageButtonga);
news1 =(ImageButton)view.findViewById(R.id.imageButtonha);
extras1 =(ImageButton)view.findViewById(R.id.imageButtonia);
homea =(ImageButton)view.findViewById(R.id.imageButtonhomea);
playera =(ImageButton)view.findViewById(R.id.imageButtonaab);
playlista =(ImageButton)view.findViewById(R.id.imageButtoncab);
downloada =(ImageButton)view.findViewById(R.id.imageButtonbab);
streama =(ImageButton)view.findViewById(R.id.imageButtondab);
wisha =(ImageButton)view.findViewById(R.id.imageButtoneab);
hita =(ImageButton)view.findViewById(R.id.imageButtonfab);
instrumenta=(ImageButton)view.findViewById(R.id.imageButtongab);
newsa =(ImageButton)view.findViewById(R.id.imageButtonhab);
extrasa =(ImageButton)view.findViewById(R.id.imageButtoniab);
miniplay= (ImageButton) view.findViewById(R.id.button2);
minisound= (ImageButton) view.findViewById(R.id.button4);
final ImageButton bP = (ImageButton) view.findViewById(R.id.left);
final ImageButton bN = (ImageButton) view.findViewById(R.id.right);
miniplay.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
if (v.getId() == R.id.minipause) {
MediaPlayer mediaPlayer= new MediaPlayer();
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
} catch (Exception e) {
e.printStackTrace();
}
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
miniplay.setImageResource(R.drawable.minipause);
} else {
mediaPlayer.pause();
miniplay.setImageResource(R.drawable.miniplay);}
}});
bP.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
bP.setVisibility(View.VISIBLE);
// bP1.setVisibility(View.GONE);
hsv.scrollTo(0, -500);
//if it's the first/last element you can bPrevoius.setEnabled(false)
}
});
bN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
bN.setVisibility(View.VISIBLE);
// bN1.setVisibility(View.GONE);
hsv.scrollTo(500, 0);
// bN.setImageResource(R.drawable.right);
}
});
home.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Home");
Fragment Home = new Home();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, Home);
fragmentTransaction.addToBackStack(null);
// fragmentTransaction.popBackStack();
fragmentTransaction.commit();
// t.setText("Player");
}});
player.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// player.setVisibility(View.VISIBLE);
// playera.setVisibility(View.GONE);
player.setEnabled(true);
t.setText("Player");
Fragment Myplayer = new MyPlayer();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, Myplayer);
fragmentTransaction.addToBackStack(null);
// fragmentTransaction.popBackStack();
fragmentTransaction.commit();
// player.setImageResource(R.drawable.player_active);
// playera.setImageResource(R.drawable.player);
}
});
}}

Resources