Reputation: 27
The image displayed on android studio and it on the emulator are different. How can i fix this? Is there any way to fix this by fixing xml or graphically?
an image on android studio and emulator
I want to add my xml here but the website doesn't allow me to do that. How can i add some code here?It says It looks like your post is mostly code; please add some more details.
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrl"
android:layout_width="match_parent"
android:layout_height="253dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="6dp">
<LinearLayout
android:id="@+id/Llayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="60sp" />
</LinearLayout>
</ScrollView>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scrl"
app:layout_constraintVertical_bias="0.51">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_one"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="clip_horizontal|center"
android:text="@string/one"
android:textSize="60sp" />
<Button
android:id="@+id/btn_two"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/two"
android:textSize="60sp" />
<Button
android:id="@+id/btn_three"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/three"
android:textSize="60sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_four"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/four"
android:textSize="60sp" />
<Button
android:id="@+id/btn_five"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/five"
android:textSize="60sp" />
<Button
android:id="@+id/btn_six"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/six"
android:textSize="60sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_seven"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/seven"
android:textSize="60sp" />
<Button
android:id="@+id/btn_eight"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/eight"
android:textSize="60sp" />
<Button
android:id="@+id/btn_nine"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/nine"
android:textSize="60sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="60sp" />
<Button
android:id="@+id/btn_zero"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/zero"
android:textSize="60sp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:onClick="onclick2"
android:text="Button"
android:visibility="visible" />
</TableRow>
</TableLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 1
Views: 44
Reputation: 304
Android Studios Design view and your emulator's screen size and dpi might be different thats why its showing diffrenet results. Try making UI that is flexable for all devices or make different layouts for different sizes.
Try something like below
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrl"
android:layout_width="match_parent"
android:layout_height="253dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="6dp">
<LinearLayout
android:id="@+id/Llayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="60sp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scrl"
app:layout_constraintVertical_bias="0.51">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="@+id/btn_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="1"
android:textSize="60sp" />
<Button
android:id="@+id/btn_two"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="2"
android:textSize="60sp" />
<Button
android:id="@+id/btn_three"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="3"
android:textSize="60sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="@+id/btn_four"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="4"
android:textSize="60sp" />
<Button
android:id="@+id/btn_five"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="5"
android:textSize="60sp" />
<Button
android:id="@+id/btn_six"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="6"
android:textSize="60sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="@+id/btn_seven"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="7"
android:textSize="60sp" />
<Button
android:id="@+id/btn_eight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="8"
android:textSize="60sp" />
<Button
android:id="@+id/btn_nine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="9"
android:textSize="60sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="@+id/btn_zero"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="clip_horizontal|center"
android:text="0"
android:textSize="60sp" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 1