简体   繁体   English

在所有设备上保持相同的视图

[英]Keep view the same on all devices

How can I change my activities xml file so that the view stays the same regardless of the size of the screen. 我如何更改我的活动xml文件,以便无论屏幕大小如何,视图都保持不变。 What I mean is the location in which the buttons or text is. 我的意思是按钮或文本所在的位置。 I want it to stay relatively the same distance and everything. 我希望它保持相对相同的距离和所有内容。 How would I do that? 我该怎么办? Would relative layout work for that or do is there something else that I would have to do in order for the view to be the same on all devices? 相对布局会为此工作还是会做其他事情,以使视图在所有设备上都相同?

XML file: XML档案:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context="com.example.navjeevenmann.mytycoon.MainActivity">


<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar2"
    android:layout_width="0dp"
    android:layout_height="59dp"
    android:background="#2C3AAD"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:text=""
    android:textColor="#000"
    android:textSize="25sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.21"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.01999998" />


<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:textColor="#000"
    android:textSize="25sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.8"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.02" />

<ImageButton
    android:id="@+id/button"
    android:layout_width="247dp"
    android:layout_height="243dp"
    android:background="#0000"
    android:src="@drawable/opengraph"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.503"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageButton
    android:id="@+id/autoclick"
    android:layout_width="49dp"
    android:layout_height="47dp"
    android:src="@drawable/cursor"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.9"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.991" />

<ImageButton
    android:id="@+id/imageview"
    android:layout_width="62dp"
    android:layout_height="58dp"
    android:adjustViewBounds="true"
    android:background="#2c3aad"
    android:maxHeight="62dp"
    android:maxWidth="5dp"
    android:scaleType="fitXY"
    android:src="@drawable/home"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0" />

<ImageButton
    android:id="@+id/singleclick"
    android:layout_width="47dp"
    android:layout_height="47dp"
    android:background="#2C3AAD"
    android:src="@drawable/singlecursor"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.99" />

<ImageButton
    android:id="@+id/imageButton2"
    android:src="@drawable/notes"
    android:layout_width="47dp"
    android:layout_height="49dp"
    android:adjustViewBounds="true"
    android:maxHeight="62dp"
    android:maxWidth="5dp"
    android:scaleType="fitXY"
    android:background="@null"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0"
    app:layout_constraintHorizontal_bias="0.047" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.100000024" />

You could use layout percentage if you want it to be same in other devices. 如果您希望在其他设备中使用相同的布局百分比,则可以使用。 Here are links that you could use for reference Percentage layout and Percent Relative Layout 这是可以用作参考的链接百分比布局相对百分比布局

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM