Scroll whole layout when keyboard is opened - java

I have created a simple Sign-In activity that looks as follows:
I had like that the whole layout will move up to the bottom of the Sign In button once the E-mail EditText is focused.
I wrote this code:
public class SignInActivity extends AppCompatActivity {
private EditText Et_Email, Et_Password;
private Button Btn_Login;
private ScrollView Sv_Layout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
initUI();
}
private void initUI() {
getSupportActionBar().hide();
Sv_Layout = findViewById( R.id.sv_SignInLayout );
Et_Email = findViewById(R.id.et_SignInEmail);
Et_Password = findViewById(R.id.et_SignInPassword);
Btn_Login = findViewById(R.id.btn_SignIn );
Et_Email.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View arg0, boolean hasfocus) {
if (hasfocus) {
focusOnView();
} else {
Log.e("TAG", "e1 not focused");
}
}
});
}
private final void focusOnView(){
Sv_Layout.post(new Runnable() {
#Override
public void run() {
Sv_Layout.scrollTo(0, Btn_Login.getBottom());
}
});
}
}
The XML is:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/sv_SignInLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
android:fillViewport="true"
tools:context=".SignInActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/iv_SignIn"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="8dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/img_signin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.2"
app:layout_constraintHorizontal_bias="0.55"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.48" />
<TextView
android:id="#+id/tv_SignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:text="#string/ActivitySignIn_SignIn"
android:textColor="#color/colorLightPurple"
android:textSize="24sp"
app:layout_constraintHeight_percent="0.05"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/iv_SignIn"
app:layout_constraintWidth_percent="0.3" />
<EditText
android:id="#+id/et_SignInEmail"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="40dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="40dp"
android:background="#drawable/btn_underline"
android:drawableStart="#drawable/ic_signin_email"
android:drawablePadding="10dp"
android:hint="#string/ActivitySignIn_EmailHint"
android:textColor="#color/colorBlackText"
android:inputType="textEmailAddress"
app:layout_constraintHeight_percent="0.06"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_SignIn" />
<EditText
android:id="#+id/et_SignInPassword"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:layout_marginTop="16dp"
android:background="#drawable/btn_underline"
android:drawableStart="#drawable/ic_login_lock"
android:drawablePadding="10dp"
android:hint="#string/ActivitySignIn_PasswordHint"
android:inputType="textPassword"
android:textColor="#color/colorBlackText"
app:layout_constraintHeight_percent="0.06"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/et_SignInEmail" />
<Button
android:id="#+id/btn_SignIn"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="40dp"
android:layout_marginBottom="80dp"
android:layout_marginEnd="40dp"
android:background="#drawable/btn_rounded_purple"
android:text="#string/ActivitySignIn_SignIn"
android:textAllCaps="false"
android:textColor="#color/colorWhite"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.08"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Is there any reason that nothing happens? I debugged the app to check if it catches the focus and it does but still, for some reason, it doesn't move the scrollview.
My manifest has android:windowSoftInputMode="adjustPan" now because if I remove it the whole layout shrinks.
Thank you!

Go with Programmatically setting the softInputLayout in onCreate of the Fragment/activity.
OR
Try out any of these,
android:windowSoftInputMode=["stateUnspecified",
"stateUnchanged", "stateHidden",
"stateAlwaysHidden", "stateVisible",
"stateAlwaysVisible", "adjustUnspecified",
"adjustResize", "adjustPan"]

Add below attribute for your activity that holds your layout in the manifest file
android:windowSoftInputMode="adjustResize"
So, for example
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.androidxtest">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Also you need to get the Button out of the ScrollView, I wrapped that into RelativeLayout
<?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=".SignInActivity">
<ScrollView
android:id="#+id/sv_SignInLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/iv_SignIn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="8dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/img_signin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.2"
app:layout_constraintHorizontal_bias="0.55"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.48" />
<TextView
android:id="#+id/tv_SignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="40dp"
android:text="#string/ActivitySignIn_SignIn"
android:textColor="#color/colorLightPurple"
android:textSize="24sp"
app:layout_constraintHeight_percent="0.05"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/iv_SignIn"
app:layout_constraintWidth_percent="0.3" />
<EditText
android:id="#+id/et_SignInEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="40dp"
android:background="#drawable/btn_underline"
android:drawableStart="#drawable/ic_signin_email"
android:drawablePadding="10dp"
android:hint="#string/ActivitySignIn_EmailHint"
android:textColor="#color/colorBlackText"
android:inputType="textEmailAddress"
app:layout_constraintHeight_percent="0.06"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_SignIn" />
<EditText
android:id="#+id/et_SignInPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:layout_marginTop="16dp"
android:background="#drawable/btn_underline"
android:drawableStart="#drawable/ic_login_lock"
android:drawablePadding="10dp"
android:hint="#string/ActivitySignIn_PasswordHint"
android:inputType="textPassword"
android:textColor="#color/colorBlackText"
app:layout_constraintHeight_percent="0.06"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/et_SignInEmail" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<Button
android:id="#+id/btn_SignIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="40dp"
android:layout_marginBottom="80dp"
android:layout_marginEnd="40dp"
android:background="#drawable/btn_rounded_purple"
android:textColor="#color/colorWhite"
android:text="sign in"
android:textAllCaps="false"
android:textSize="20sp" />
</RelativeLayout>

Related

Hello ,my app crashes every time I invoke Spinner which exists in a Fragment called "Firstfragment"

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//This Spinner is not located in the MainActivity but in A fragment
Spinner s = (Spinner) findViewById(R.id.spinner33);
s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String msupplier=s.getSelectedItem().toString();
Log.e("Selected item : ", msupplier);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
//Main MainActivity
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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"
android:id="#+id/drawer">
<include
layout="#layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="104dp"
app:headerLayout="#layout/nav_header"
app:menu="#menu/nav_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
//first Fragment
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/Fragment1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2196F3"
tools:context=".MainActivity">
<ImageView
android:id="#+id/imageView4"
android:layout_width="match_parent"
android:layout_height="773dp"
android:src="#mipmap/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/teal_700"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="#+id/watBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:drawableTop="#drawable/ic_baseline_looks_one_24"
android:editable="true"
android:enabled="true"
android:focusable="auto"
android:gravity="center"
android:includeFontPadding="true"
android:linksClickable="true"
android:onClick="WattMthd"
android:text="#string/WAT"
app:backgroundTint="#android:color/holo_blue_dark"
tools:layout_editor_absoluteX="35dp"
tools:layout_editor_absoluteY="129dp" />
<Button
android:id="#+id/ampBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/ic_baseline_looks_two_24"
android:editable="true"
android:gravity="center"
android:onClick="ampMthd"
android:text="#string/AMP"
android:textColorLink="#FFFFFF"
app:backgroundTint="#android:color/darker_gray" />
<Button
android:id="#+id/voltBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/ic_baseline_looks_3_24"
android:editable="true"
android:gravity="center"
android:onClick="voltMthd"
android:text="فولت"
app:backgroundTint="#android:color/holo_blue_dark" />
<Button
android:id="#+id/kWbtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/ic_baseline_looks_4_24"
android:editable="true"
android:gravity="center"
android:onClick="kWMthd"
android:text="كيلو"
app:backgroundTint="#android:color/holo_blue_dark" />
</LinearLayout>
<Spinner
android:id="#+id/spinner33"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray"
android:dropDownWidth="match_parent"
android:entries="#array/SpinerConvertFrom"
android:foreground="#drawable/ic_baseline_arrow_drop_down_circle_24"
android:foregroundGravity="left|center"
android:gravity="center"
android:textAlignment="center"
android:visibility="visible"
app:flow_verticalAlign="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spinner33">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/Text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/AMP"
android:inputType="numberDecimal"
android:selectAllOnFocus="true"
android:textAlignment="center" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/Volt"
android:inputType="numberDecimal"
android:selectAllOnFocus="true"
android:textAlignment="center" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
If you are calling the spinner initialization from the fragment but it exists in the main activity it will crash, you need to call it in the activity, or move it to the xml of the framgnet.
activity_main belongs to MainActivity. So there is a fragment_first which belongs to FirstFragment. The spinner you are trying to initialize belongs to fragment_first, so you have to use it inside FirstFragment or move it (spinner) to activity_main
Hi bro inside you activity_main.xml you didn't define spinner, so you can't get view which you didn't create in your xml file, you can get it from your fragment, or you must move Spinner to activity_main.xml.

How to make PlayerView full screen in landscape mode when used in MotionLayout

I want to make it possible to make the PlayerView in landscape mode full screen but I can't make it work. So far, I have tried to set the playerView layout params programmatically when configuration changes to landscape mode, but it still isn't working.
Layout that I have created
<androidx.constraintlayout.motion.widget.MotionLayout 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/player_motion_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax"
app:layoutDescription="#xml/vod_player_scene"
app:viewToDetectTouch="#id/top_player_container">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/top_player_container"
android:layout_width="match_parent"
android:layout_height="280dp"
android:background="#272727"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/playerView"
android:layout_width="match_parent"
android:layout_height="280dp"
android:focusable="true"
app:controller_layout_id="#layout/exo_playback_control_view_vod"
app:fastforward_increment="10000"
app:hide_on_touch="true"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:resize_mode="fixed_width"
app:rewind_increment="10000"
app:show_timeout="2000" />
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="64dp"
android:layout_height="64dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="#id/playerView"
app:layout_constraintEnd_toEndOf="#id/playerView"
app:layout_constraintStart_toStartOf="#id/playerView"
app:layout_constraintTop_toTopOf="#id/playerView" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/image_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:alpha="0"
app:layout_constraintBottom_toBottomOf="#id/top_player_container"
app:layout_constraintEnd_toStartOf="#id/image_clear"
app:layout_constraintTop_toTopOf="#id/top_player_container"
app:srcCompat="#drawable/ic_play_arrow_32dp"
app:tint="#color/white" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/image_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:alpha="0"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintBottom_toBottomOf="#id/top_player_container"
app:layout_constraintEnd_toEndOf="#id/top_player_container"
app:layout_constraintTop_toTopOf="#id/top_player_container"
app:srcCompat="#drawable/ic_clear_32dp"
app:tint="#color/white" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/video_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:ellipsize="end"
android:fontFamily="#font/montserrat_semi_bold"
android:maxLines="1"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="#id/top_player_container"
app:layout_constraintEnd_toStartOf="#id/image_play"
app:layout_constraintStart_toEndOf="#id/playerView"
app:layout_constraintTop_toTopOf="#id/top_player_container"
tools:text="Blade Runner" />
<FrameLayout
android:id="#+id/recyclerview_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/video_club_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/top_player_container" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview_front"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/video_club_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/top_player_container" />
<ProgressBar
android:id="#+id/recyclerView_progressView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="#id/recyclerview_front"
app:layout_constraintStart_toStartOf="#id/recyclerview_front"
app:layout_constraintTop_toTopOf="#id/recyclerview_front" />
</androidx.constraintlayout.motion.widget.MotionLayout>
And programatically, I am doing it this way (see below code)
#Override
public void onConfigurationChanged(#NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int newOrientation = newConfig.orientation;
if (newOrientation == Configuration.ORIENTATION_LANDSCAPE) {
MotionLayout.LayoutParams params = (MotionLayout.LayoutParams)
getPlayerView().getLayoutParams();
params.width = params.MATCH_PARENT;
params.height = params.MATCH_PARENT;
getPlayerView().setLayoutParams(params);
} else {
}
}
Also in Manifest.xml I have declared activity as
<activity
android:name=".main.MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
android:label="#string/app_name"
android:theme="#style/MainTheme"
android:windowSoftInputMode="adjustPan" />
Let me know if you need anything else to share with you.
Thanks in advance.
To be able to change any of the views that have MotionLayout as parent, we should work with MotionScene.
What I did to fix this problem, I created two functions, one to make playerView width and height to MATCH_PARENT and the other to reset it to previous state (when screen orientation back to portrait).
private void setPlayerToMatchHeight() {
ConstraintSet expandedSet = getMotionLayout().getConstraintSet(R.id.expanded);
ConstraintSet.Constraint topPlayerContainerSet = expandedSet.getConstraint(R.id.top_player_container);
topPlayerContainerSet.layout.mHeight = ViewGroup.LayoutParams.MATCH_PARENT;
}
private void setPlayerTo16x9dimensionRatio() {
ConstraintSet expandedSet = getMotionLayout().getConstraintSet(R.id.expanded);
ConstraintSet.Constraint topPlayerContainerSet = expandedSet.getConstraint(R.id.top_player_container);
topPlayerContainerSet.layout.mHeight = 0;
topPlayerContainerSet.layout.dimensionRatio = "16:9";
}
And then, in onConfigurationChanged, based on newOrientation, I call these functions respectively.

Android ... My application doesn't launch?

So, I am trying to do an application which gives a user the ability to keep track of the score and number of fouls of two different teams playing football
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:padding="4dp"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:text="Team A"
android:textColor="#616161"
android:textSize="14sp" />
<TextView
android:id="#+id/team_a_goal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:padding="4dp"
android:paddingBottom="24dp"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:text="0"
android:textColor="#000000"
android:textSize="56sp" />
<TextView
android:id="#+id/team_a_foul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:padding="4dp"
android:paddingBottom="24dp"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:text="0"
android:textColor="#000000"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginBottom="8dp"
android:onClick="addGoalForTeamA"
android:text="GOAL" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginBottom="8dp"
android:onClick="addFoulForTeamA"
android:text="FOUL" />
</LinearLayout>
<view
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/darker_gray" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:padding="4dp"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:text="Team B"
android:textColor="#616161"
android:textSize="14sp" />
<TextView
android:id="#+id/team_b_goal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:padding="4dp"
android:paddingBottom="24dp"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:text="0"
android:textColor="#000000"
android:textSize="56sp" />
<TextView
android:id="#+id/team_b_foul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:padding="4dp"
android:paddingBottom="24dp"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:text="0"
android:textColor="#000000"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginBottom="8dp"
android:onClick="addGoalForTeamB"
android:text="GOAL" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginBottom="8dp"
android:onClick="addFoulForTeamB"
android:text="FOUL" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
android:onClick="Reset"
android:text="Reset" />
and java code
package com.example.android.scorekeeper;
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int goalTeamA = 0;
int foulTeamA = 0;
int goalTeamB = 0;
int foulTeamB = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void addGoalForTeamA(View view) {
goalTeamA = +1;
displayGoalTeamA(goalTeamA);
}
public void addFoulForTeamA(View view) {
foulTeamA = +1;
displayFoulTeamA(foulTeamA);
}
public void addGoalForTeamB(View view) {
goalTeamB = +1;
displayGoalTeamB(goalTeamB);
}
public void addFoulForTeamB(View view) {
foulTeamB = +1;
displayFoulTeamB(foulTeamB);
}
public void Reset(View view) {
goalTeamA = 0;
foulTeamA = 0;
goalTeamB = 0;
foulTeamB = 0;
displayGoalTeamA(goalTeamA);
displayFoulTeamA(foulTeamA);
displayGoalTeamB(goalTeamB);
displayFoulTeamB(foulTeamB);
}
public void displayGoalTeamA(int score) {
TextView scoreView = findViewById(R.id.team_a_goal);
scoreView.setText(String.valueOf(score));
}
public void displayFoulTeamA(int score) {
TextView scoreView = findViewById(R.id.team_a_foul);
scoreView.setText(String.valueOf(score));
}
public void displayGoalTeamB(int score) {
TextView scoreView = findViewById(R.id.team_b_goal);
scoreView.setText(String.valueOf(score));
}
public void displayFoulTeamB(int score) {
TextView scoreView = findViewById(R.id.team_b_foul);
scoreView.setText(String.valueOf(score));
} }
The code seems fine to me and Android Studio doesn't report any errors but it did't launch on my android
make sure you have added your activity to your manifest file
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Android Studio: Using ImageButton to start new activity crashes the app

I am designing an app that has a home screen with 6 image buttons, that all start new activities.
Currently when I press the button, the app crashes. This is strange however as I have done this project with regular buttons and it works fine, and I have also made it so when the image button is pressed it just prints "Clicked!" on thee screen and this also works fine, so the problem is starting a new activity.
MainActivity.java
package com.example.darren1.homemanagementsystem;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.widget.Button;
import android.widget.ImageButton;
import android.view.View.OnClickListener;
import android.view.View;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findAllViewsById();
}
private void findAllViewsById(){
ImageButton lightButton = (ImageButton) findViewById(R.id.lightButton);
lightButton.setOnClickListener(new View.OnClickListener() {
public void onClick (View v){
Intent intent = new Intent(MainActivity.this, LightingActivity.class);
startActivity(intent);
}
});
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#feae5e"
android:clickable="true">
<GridLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:background="#feae5e"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true">
<ImageButton
android:layout_width="137dp"
android:layout_height="133dp"
android:id="#+id/cameraButton"
android:layout_row="0"
android:layout_column="0"
android:src="#drawable/rsz_cameraicon"
android:background="#feae5e" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/alarmButton"
android:layout_row="0"
android:layout_column="13"
android:src="#drawable/rsz_alarmicon"
android:background="#feae5e" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fireButton"
android:layout_row="1"
android:layout_column="0"
android:src="#drawable/rsz_fireicon"
android:background="#feae5e"
android:layout_marginTop="40dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lightButton"
android:layout_row="1"
android:layout_column="13"
android:src="#drawable/rsz_lightbulbicon"
android:background="#feae5e"
android:layout_marginTop="40dp"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/thermoButton"
android:layout_row="2"
android:layout_column="0"
android:src="#drawable/rsz_1thermometericon"
android:background="#feae5e"
android:layout_marginTop="40dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvButton"
android:layout_row="2"
android:layout_column="13"
android:src="#drawable/rsz_1tvicon"
android:background="#feae5e"
android:layout_marginTop="40dp" />
</GridLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.darren1.homemanagementsystem" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LightingActivity"
android:label="Light" >
</activity>
<activity android:name=".TelevisionActivity"
android:label="TV">
</activity>
</application>
activity_lighting.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.darren1.homemanagementsystem.LightingActivity"
android:background="#beddeb">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_alignParentStart="false"
android:id="#+id/linearLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/lighting"
android:id="#+id/lightingView"
android:layout_gravity="center_horizontal"
android:textSize="32dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_below="#+id/linearLayout"
android:layout_alignParentStart="true"
android:layout_marginTop="66dp"
android:id="#+id/linearLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/kitchen"
android:id="#+id/kitchenLight" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/sittingroom"
android:id="#+id/sittingroomLight"
android:layout_marginTop="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/bedroom"
android:id="#+id/bedroomLight"
android:layout_marginTop="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/outside"
android:id="#+id/outsideLight"
android:layout_marginTop="20dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_alignTop="#+id/linearLayout2"
android:layout_alignEnd="#+id/linearLayout"
android:id="#+id/linearLayout3">
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/switch1" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/switch2"
android:layout_marginTop="20dp" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/switch3"
android:layout_marginTop="20dp" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/switch4"
android:checked="false"
android:layout_marginTop="20dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="#string/backButton"
android:id="#+id/backButton"
android:layout_gravity="center_horizontal"
android:background="#010101"
android:textColor="#fefdfd"
android:textStyle="bold"
android:textSize="20dp" />
</LinearLayout>
LightingActivity.java
package com.example.darren1.homemanagementsystem;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View.OnClickListener;
public class LightingActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setTitle("Light");
setContentView(R.layout.activity_lighting);
onClickListenerButton();
}
public void onClickListenerButton(){
Intent i = getIntent();
}
}
The problem I guess comes with this two lines :
getActionBar().setTitle("Light");
setContentView(R.layout.activity_lighting);
You should put frist the setContentView() and then the Title of your ActionBar
If I were you I'd start using [Toolbar](http://developer.android.com/reference/android/widget/Toolbar.html)
Do thesetTitle()` as follows :
ActionBar actionBar = getActionBar();
actionBar.setTitle("Light");
See this answer for more detail
Not correct:
setContentView(R.layout.activity_light); -> activity_lighting.xml
Different name.
But you have another different name:
setContentView(R.layout.activity_main); -> activity_mainn.xml
(Maybe typing error)

The keyboard is coming upon the EditText field & thus hiding it. How to prevent the keyboard from hiding the EditText field?

My EditText is at the bottom of screen, so when I'm tapping on it to edit it, the keyboard is hiding it. I want that when I tap on EditText, the keyboard should remain below it & should not hide it.
Here's the link to the screenshot showing EditText before tapping on it: http://imgur.com/cgme1HT
Here's the link to the screenshot after tapping on EditText (the EditText field is below the keyboard now): http://imgur.com/nloFrkn
Here's my SettingUpUserProfile.java file's code:
public class SettingUpUserProfile extends AppCompatActivity {
public static final int TAKE_PHOTO_REQUEST = 0;
public static final int PICK_PHOTO_REQUEST = 1;
private static final int RESULT_LOAD_IMG = 2;
String imgDecodableString;
protected ImageView userProfilePicture;
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting_up_user_profile);
userProfilePicture = (ImageView) findViewById(R.id.userProfilePicture);
userProfilePicture.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(SettingUpUserProfile.this);
builder.setTitle(null);
builder.setItems(R.array.pickImage_options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int position) {
switch (position) {
case 0:
Intent intentCaptureFromCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intentCaptureFromCamera, TAKE_PHOTO_REQUEST);
break;
case 1:
Intent chooseFromGalley = new Intent(Intent.ACTION_GET_CONTENT);
chooseFromGalley.setType("image/*");
startActivityForResult(chooseFromGalley, PICK_PHOTO_REQUEST);
break;
}
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
Uri uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
// Log.d(TAG, String.valueOf(bitmap));
ImageView imageView = (ImageView) findViewById(R.id.userProfilePicture);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
}
Here's my activity_setting_up_user_profile.xml file's code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_purple"
tools:context="com.abc.xyz.SettingUpUserProfile">
<TextView
android:id="#+id/settingUpUserProfileText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="#string/settingUpUserProfileText1"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="30sp"
android:gravity="center_horizontal|center_vertical"/>
<ImageView
android:id="#+id/userProfilePicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#+id/settingUpUserProfileText1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="100dp"
android:clickable="true"
android:src="#drawable/ic_face_white_48dp" />
<TextView
android:id="#+id/settingUpUserProfileText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userProfilePicture"
android:layout_marginTop="5dp"
android:text="#string/settingUpUserProfileText2"
android:textColor="#color/white"
android:textSize="15sp"
android:gravity="center_horizontal|center_vertical"/>
<EditText
android:id="#+id/userName"
android:background="#drawable/phone_number_edit_text_design"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/settingUpUserProfileText2"
android:layout_marginTop="80dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:gravity="center_horizontal|center_vertical"
android:hint="#string/hint_userName"
android:textColor="#color/white"
android:textColorHint="#E0E0E0"
android:textCursorDrawable="#null"
android:inputType="textPersonName"/>
<Button
android:id="#+id/buttonAllSet"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_marginTop="20dp"
android:text="#string/button_allSet"
android:textStyle="bold"
android:textColor="#color/light_purple"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:gravity="center_horizontal|center_vertical"/>
</RelativeLayout>
I really have no clue about what to do here!
Please let me know.
I'm new to StackOverflow, so please cooperate.
Thanks in advance.
I had the same issue where the softkeyboard was on top of the EditText views which were placed on the bottom of the screen. I was able to find a solution by adding a single line to my AndroidManifest.xml file's relevant activity.
Put layout inside a ScrollView.
android:windowSoftInputMode="adjustResize|stateHidden"
This is how the whole activity tag looks like:
<activity
android:name="com.my.MainActivity"
android:screenOrientation="portrait"
android:label="#string/title_activity_main"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
Here the most important value is the adjustResize. This will shift the whole UI up to give room for the softkeyboard.
Simply use a ScrollView as the parent view in your xml file.
Options-1
Try using android:windowSoftInputMode="adjustPan" in activity in AndroidManifest.xml
Options-2
Use ScrollView as parent in xml. Replace your xml with this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.abc.xyz.SettingUpUserProfile" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_purple">
<TextView
android:id="#+id/settingUpUserProfileText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="#string/settingUpUserProfileText1"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="30sp"
android:gravity="center_horizontal|center_vertical"/>
<ImageView
android:id="#+id/userProfilePicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#+id/settingUpUserProfileText1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="100dp"
android:clickable="true"
android:src="#drawable/ic_face_white_48dp" />
<TextView
android:id="#+id/settingUpUserProfileText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userProfilePicture"
android:layout_marginTop="5dp"
android:text="#string/settingUpUserProfileText2"
android:textColor="#color/white"
android:textSize="15sp"
android:gravity="center_horizontal|center_vertical"/>
<EditText
android:id="#+id/userName"
android:background="#drawable/phone_number_edit_text_design"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/settingUpUserProfileText2"
android:layout_marginTop="80dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:gravity="center_horizontal|center_vertical"
android:hint="#string/hint_userName"
android:textColor="#color/white"
android:textColorHint="#E0E0E0"
android:textCursorDrawable="#null"
android:inputType="textPersonName"/>
<Button
android:id="#+id/buttonAllSet"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_marginTop="20dp"
android:text="#string/button_allSet"
android:textStyle="bold"
android:textColor="#color/light_purple"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:gravity="center_horizontal|center_vertical"/>
</RelativeLayout>
</ScrollView>
Thank you all for your answers.
I solved the problem by changing my activity_setting_up_user_profile.xml file's code to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/light_purple"
tools:context="com.abc.xyz.SettingUpUserProfile" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/settingUpUserProfileText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/settingUpUserProfileText1"
android:textColor="#color/white"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/userProfilePicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#+id/settingUpUserProfileText1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="100dp"
android:clickable="true"
android:src="#drawable/ic_face_white_48dp" />
<TextView
android:id="#+id/settingUpUserProfileText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userProfilePicture"
android:layout_marginTop="5dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/settingUpUserProfileText2"
android:textColor="#color/white"
android:textSize="15sp" />
<EditText
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/settingUpUserProfileText2"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="80dp"
android:background="#drawable/phone_number_edit_text_design"
android:gravity="center_horizontal|center_vertical"
android:hint="#string/hint_userName"
android:inputType="textPersonName"
android:textColor="#color/white"
android:textColorHint="#E0E0E0"
android:textCursorDrawable="#null" />
<Button
android:id="#+id/buttonAllSet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:layout_marginTop="20dp"
android:background="#color/white"
android:gravity="center_horizontal|center_vertical"
android:text="#string/button_allSet"
android:textColor="#color/light_purple"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
This was COOL!
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.abc.xyz.SettingUpUserProfile" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_purple" >
<TextView
android:id="#+id/settingUpUserProfileText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/settingUpUserProfileText1"
android:textColor="#color/white"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/userProfilePicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#+id/settingUpUserProfileText1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="100dp"
android:clickable="true"
android:src="#drawable/ic_face_white_48dp" />
<TextView
android:id="#+id/settingUpUserProfileText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userProfilePicture"
android:layout_marginTop="5dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/settingUpUserProfileText2"
android:textColor="#color/white"
android:textSize="15sp" />
<EditText
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/settingUpUserProfileText2"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="80dp"
android:background="#drawable/phone_number_edit_text_design"
android:gravity="center_horizontal|center_vertical"
android:hint="#string/hint_userName"
android:inputType="textPersonName"
android:textColor="#color/white"
android:textColorHint="#E0E0E0"
android:textCursorDrawable="#null" />
<Button
android:id="#+id/buttonAllSet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:layout_marginTop="20dp"
android:background="#color/white"
android:gravity="center_horizontal|center_vertical"
android:text="#string/button_allSet"
android:textColor="#color/light_purple"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</ScrollView>

Categories