How to center 2 edit texts and a button below horizontally
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I want to achieve the following look for a login activity, but it looks quite different on different devices I'm testing.
center
Edit: This is the current code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/icon"
android:src="@drawable/icon" />
<EditText
android:id="@+id/emailField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/passwordField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>
As you can see on the design tab it looks ok, but I can't move it up or down, and on different devices it's not exactly centered:
Current layout
android
add a comment |
I want to achieve the following look for a login activity, but it looks quite different on different devices I'm testing.
center
Edit: This is the current code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/icon"
android:src="@drawable/icon" />
<EditText
android:id="@+id/emailField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/passwordField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>
As you can see on the design tab it looks ok, but I can't move it up or down, and on different devices it's not exactly centered:
Current layout
android
How does it look on your devices? What code are you using? Show us to help you
– Ivan
Nov 26 '18 at 16:57
I added the coed and image of the code, I can't move it up or down as I wish, it's stuck up there
– Stackpile
Nov 26 '18 at 17:04
add a comment |
I want to achieve the following look for a login activity, but it looks quite different on different devices I'm testing.
center
Edit: This is the current code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/icon"
android:src="@drawable/icon" />
<EditText
android:id="@+id/emailField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/passwordField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>
As you can see on the design tab it looks ok, but I can't move it up or down, and on different devices it's not exactly centered:
Current layout
android
I want to achieve the following look for a login activity, but it looks quite different on different devices I'm testing.
center
Edit: This is the current code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/icon"
android:src="@drawable/icon" />
<EditText
android:id="@+id/emailField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/passwordField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>
As you can see on the design tab it looks ok, but I can't move it up or down, and on different devices it's not exactly centered:
Current layout
android
android
edited Nov 26 '18 at 17:04
Stackpile
asked Nov 26 '18 at 16:54
StackpileStackpile
647
647
How does it look on your devices? What code are you using? Show us to help you
– Ivan
Nov 26 '18 at 16:57
I added the coed and image of the code, I can't move it up or down as I wish, it's stuck up there
– Stackpile
Nov 26 '18 at 17:04
add a comment |
How does it look on your devices? What code are you using? Show us to help you
– Ivan
Nov 26 '18 at 16:57
I added the coed and image of the code, I can't move it up or down as I wish, it's stuck up there
– Stackpile
Nov 26 '18 at 17:04
How does it look on your devices? What code are you using? Show us to help you
– Ivan
Nov 26 '18 at 16:57
How does it look on your devices? What code are you using? Show us to help you
– Ivan
Nov 26 '18 at 16:57
I added the coed and image of the code, I can't move it up or down as I wish, it's stuck up there
– Stackpile
Nov 26 '18 at 17:04
I added the coed and image of the code, I can't move it up or down as I wish, it's stuck up there
– Stackpile
Nov 26 '18 at 17:04
add a comment |
2 Answers
2
active
oldest
votes
add the views in a constraint layout and add a horizontal guideline at the percentage of the screen that you want your views to begin. Then just constrain your views underneath that, one after the other, and constrain their sides to match the parent:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:contentDescription="@string/icon"
android:src="@drawable/icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline2"
/>
<EditText
android:id="@+id/emailField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/icon"
/>
<EditText
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emailField"
/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordField"
/>
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</android.support.constraint.ConstraintLayout>
This should be the approach. Its the right and most efficient way of doing it.
– codeFood
Nov 26 '18 at 20:43
from some reason when I copy paste it the view is blank (nothing appears in the design tab)
– Stackpile
Nov 26 '18 at 22:03
But the guideline you mentions talks aboust the percentage of height, I was talking about making the text views at width of 70% for example
– Stackpile
Nov 27 '18 at 9:13
sometimes you need to build the project first, before anything appears on the design tab. Also, the guidelines can be horizontal or vertical, just change the orientation attribute and adjust the percentage. If the line changes orientation though, the views that are constraint by it, will need to be adjusted as well
– Nikos Hidalgo
Nov 27 '18 at 9:38
add a comment |
How about a RelativeLayout
and android:layout_centerInParent="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/icon"
android:src="@drawable/icon" />
<EditText
android:id="@+id/emailField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/passwordField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
Is it possible to "play" with the width of the button and edit texts as percentage? for example if I want the width of the button and the edit texts to be 70 percent of the width, what can I do?
– Stackpile
Nov 26 '18 at 22:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53485728%2fhow-to-center-2-edit-texts-and-a-button-below-horizontally%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
add the views in a constraint layout and add a horizontal guideline at the percentage of the screen that you want your views to begin. Then just constrain your views underneath that, one after the other, and constrain their sides to match the parent:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:contentDescription="@string/icon"
android:src="@drawable/icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline2"
/>
<EditText
android:id="@+id/emailField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/icon"
/>
<EditText
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emailField"
/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordField"
/>
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</android.support.constraint.ConstraintLayout>
This should be the approach. Its the right and most efficient way of doing it.
– codeFood
Nov 26 '18 at 20:43
from some reason when I copy paste it the view is blank (nothing appears in the design tab)
– Stackpile
Nov 26 '18 at 22:03
But the guideline you mentions talks aboust the percentage of height, I was talking about making the text views at width of 70% for example
– Stackpile
Nov 27 '18 at 9:13
sometimes you need to build the project first, before anything appears on the design tab. Also, the guidelines can be horizontal or vertical, just change the orientation attribute and adjust the percentage. If the line changes orientation though, the views that are constraint by it, will need to be adjusted as well
– Nikos Hidalgo
Nov 27 '18 at 9:38
add a comment |
add the views in a constraint layout and add a horizontal guideline at the percentage of the screen that you want your views to begin. Then just constrain your views underneath that, one after the other, and constrain their sides to match the parent:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:contentDescription="@string/icon"
android:src="@drawable/icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline2"
/>
<EditText
android:id="@+id/emailField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/icon"
/>
<EditText
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emailField"
/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordField"
/>
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</android.support.constraint.ConstraintLayout>
This should be the approach. Its the right and most efficient way of doing it.
– codeFood
Nov 26 '18 at 20:43
from some reason when I copy paste it the view is blank (nothing appears in the design tab)
– Stackpile
Nov 26 '18 at 22:03
But the guideline you mentions talks aboust the percentage of height, I was talking about making the text views at width of 70% for example
– Stackpile
Nov 27 '18 at 9:13
sometimes you need to build the project first, before anything appears on the design tab. Also, the guidelines can be horizontal or vertical, just change the orientation attribute and adjust the percentage. If the line changes orientation though, the views that are constraint by it, will need to be adjusted as well
– Nikos Hidalgo
Nov 27 '18 at 9:38
add a comment |
add the views in a constraint layout and add a horizontal guideline at the percentage of the screen that you want your views to begin. Then just constrain your views underneath that, one after the other, and constrain their sides to match the parent:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:contentDescription="@string/icon"
android:src="@drawable/icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline2"
/>
<EditText
android:id="@+id/emailField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/icon"
/>
<EditText
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emailField"
/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordField"
/>
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</android.support.constraint.ConstraintLayout>
add the views in a constraint layout and add a horizontal guideline at the percentage of the screen that you want your views to begin. Then just constrain your views underneath that, one after the other, and constrain their sides to match the parent:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:contentDescription="@string/icon"
android:src="@drawable/icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline2"
/>
<EditText
android:id="@+id/emailField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/icon"
/>
<EditText
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emailField"
/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordField"
/>
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</android.support.constraint.ConstraintLayout>
edited Nov 26 '18 at 17:29
answered Nov 26 '18 at 17:14
Nikos HidalgoNikos Hidalgo
1,3132418
1,3132418
This should be the approach. Its the right and most efficient way of doing it.
– codeFood
Nov 26 '18 at 20:43
from some reason when I copy paste it the view is blank (nothing appears in the design tab)
– Stackpile
Nov 26 '18 at 22:03
But the guideline you mentions talks aboust the percentage of height, I was talking about making the text views at width of 70% for example
– Stackpile
Nov 27 '18 at 9:13
sometimes you need to build the project first, before anything appears on the design tab. Also, the guidelines can be horizontal or vertical, just change the orientation attribute and adjust the percentage. If the line changes orientation though, the views that are constraint by it, will need to be adjusted as well
– Nikos Hidalgo
Nov 27 '18 at 9:38
add a comment |
This should be the approach. Its the right and most efficient way of doing it.
– codeFood
Nov 26 '18 at 20:43
from some reason when I copy paste it the view is blank (nothing appears in the design tab)
– Stackpile
Nov 26 '18 at 22:03
But the guideline you mentions talks aboust the percentage of height, I was talking about making the text views at width of 70% for example
– Stackpile
Nov 27 '18 at 9:13
sometimes you need to build the project first, before anything appears on the design tab. Also, the guidelines can be horizontal or vertical, just change the orientation attribute and adjust the percentage. If the line changes orientation though, the views that are constraint by it, will need to be adjusted as well
– Nikos Hidalgo
Nov 27 '18 at 9:38
This should be the approach. Its the right and most efficient way of doing it.
– codeFood
Nov 26 '18 at 20:43
This should be the approach. Its the right and most efficient way of doing it.
– codeFood
Nov 26 '18 at 20:43
from some reason when I copy paste it the view is blank (nothing appears in the design tab)
– Stackpile
Nov 26 '18 at 22:03
from some reason when I copy paste it the view is blank (nothing appears in the design tab)
– Stackpile
Nov 26 '18 at 22:03
But the guideline you mentions talks aboust the percentage of height, I was talking about making the text views at width of 70% for example
– Stackpile
Nov 27 '18 at 9:13
But the guideline you mentions talks aboust the percentage of height, I was talking about making the text views at width of 70% for example
– Stackpile
Nov 27 '18 at 9:13
sometimes you need to build the project first, before anything appears on the design tab. Also, the guidelines can be horizontal or vertical, just change the orientation attribute and adjust the percentage. If the line changes orientation though, the views that are constraint by it, will need to be adjusted as well
– Nikos Hidalgo
Nov 27 '18 at 9:38
sometimes you need to build the project first, before anything appears on the design tab. Also, the guidelines can be horizontal or vertical, just change the orientation attribute and adjust the percentage. If the line changes orientation though, the views that are constraint by it, will need to be adjusted as well
– Nikos Hidalgo
Nov 27 '18 at 9:38
add a comment |
How about a RelativeLayout
and android:layout_centerInParent="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/icon"
android:src="@drawable/icon" />
<EditText
android:id="@+id/emailField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/passwordField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
Is it possible to "play" with the width of the button and edit texts as percentage? for example if I want the width of the button and the edit texts to be 70 percent of the width, what can I do?
– Stackpile
Nov 26 '18 at 22:21
add a comment |
How about a RelativeLayout
and android:layout_centerInParent="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/icon"
android:src="@drawable/icon" />
<EditText
android:id="@+id/emailField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/passwordField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
Is it possible to "play" with the width of the button and edit texts as percentage? for example if I want the width of the button and the edit texts to be 70 percent of the width, what can I do?
– Stackpile
Nov 26 '18 at 22:21
add a comment |
How about a RelativeLayout
and android:layout_centerInParent="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/icon"
android:src="@drawable/icon" />
<EditText
android:id="@+id/emailField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/passwordField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
How about a RelativeLayout
and android:layout_centerInParent="true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/icon"
android:src="@drawable/icon" />
<EditText
android:id="@+id/emailField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/passwordField"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
answered Nov 26 '18 at 17:15
forpasforpas
19.9k4830
19.9k4830
Is it possible to "play" with the width of the button and edit texts as percentage? for example if I want the width of the button and the edit texts to be 70 percent of the width, what can I do?
– Stackpile
Nov 26 '18 at 22:21
add a comment |
Is it possible to "play" with the width of the button and edit texts as percentage? for example if I want the width of the button and the edit texts to be 70 percent of the width, what can I do?
– Stackpile
Nov 26 '18 at 22:21
Is it possible to "play" with the width of the button and edit texts as percentage? for example if I want the width of the button and the edit texts to be 70 percent of the width, what can I do?
– Stackpile
Nov 26 '18 at 22:21
Is it possible to "play" with the width of the button and edit texts as percentage? for example if I want the width of the button and the edit texts to be 70 percent of the width, what can I do?
– Stackpile
Nov 26 '18 at 22:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53485728%2fhow-to-center-2-edit-texts-and-a-button-below-horizontally%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How does it look on your devices? What code are you using? Show us to help you
– Ivan
Nov 26 '18 at 16:57
I added the coed and image of the code, I can't move it up or down as I wish, it's stuck up there
– Stackpile
Nov 26 '18 at 17:04