3

The Android user interface displays the graphic and AVD layout differently

 2 years ago
source link: https://www.codesd.com/item/the-android-user-interface-displays-the-graphic-and-avd-layout-differently.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

The Android user interface displays the graphic and AVD layout differently

advertisements

I try to make a rouned EditText.It display well in the Graphical layout in main.xml. But it is still square when i launch the AVD.Here is the code:

<EditText
        android:id="@+id/et"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:hint="Enter a #hashtag or keyword"
        android:textColor="#000000"
        android:drawableLeft="@drawable/magnifier"
        android:background="@drawable/rounded_edittext"
        android:textSize="16dp" >
        <requestFocus />
    </EditText>
<!-- res/drawable/rounded_edittext.xml -->     <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners
    android:bottomLeftRadius="15dp"
    android:bottomRightRadius="15dp"
    android:topLeftRadius="15dp"
    android:topRightRadius="15dp" />


This a rounded edit text that change also behavour on clik states, Simply use thes xml

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext_states.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
     android:state_pressed="true"
     android:state_enabled="true"
        android:drawable="@drawable/rounded_focused" />
    <item
     android:state_focused="true"
     android:state_enabled="true"
        android:drawable="@drawable/rounded_focused" />
    <item
     android:state_enabled="true"
        android:drawable="@drawable/rounded_edittext" />
</selector>

Normal rounded edittext:

<?xml version="1.0" encoding="utf-8"?>
<!--  res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
 <solid android:color="#FFFFFF"/>
    <corners
     android:bottomRightRadius="15dp"
     android:bottomLeftRadius="15dp"
  android:topLeftRadius="15dp"
  android:topRightRadius="15dp"/>
</shape>

Pressed,Focused edittext

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext_focused.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
 <solid android:color="#FFFFFF"/>
 <stroke android:width="2dp" android:color="#FF0000" />
    <corners
     android:bottomRightRadius="15dp"
     android:bottomLeftRadius="15dp"
  android:topLeftRadius="15dp"
  android:topRightRadius="15dp"/>
</shape>

And... now, the EditText should look like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:background="@drawable/rounded_edittext_states"
    android:padding="5dip"/>
</LinearLayout>

i used this layout to test it for and it works for me even with multiple round edittext:

this is the layout i use

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/et"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_edittext"
        android:drawableLeft="@drawable/ic_launcher"
        android:hint="Enter a Login"
        android:textColor="#000000"
        android:textSize="16dp"
        android:padding="5dp">
        <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/et2"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/et"
            android:layout_marginTop="14dp"
            android:background="@drawable/rounded_edittext"
            android:drawableLeft="@drawable/ic_launcher"
            android:ems="10"
            android:hint="Enter a Password"
            android:padding="5dp"
            android:textColor="#000000"
            android:textSize="16dp" />

</RelativeLayout>

and this is a screen capture of the result on emulator:

COVX3.jpg

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK