简体   繁体   English

Android EditText垂直大小调整:我希望它很小!

[英]Android EditText vertical sizing: I want it to be small!

Here are sample pictures of two EditText fields I've added in an Action Bar: 这是我在操作栏中添加的两个EditText字段的示例图片: 这是从图形视图

[This is from the Graphical Layout tool in Eclipse] [这是来自Eclipse中的图形布局工具] 在此处输入图片说明

[This is what it looks like in my emulator (2.1 WVGA854) [这是我的模拟器(2.1 WVGA854)的外观

My question is, how can I make the EditText look a bit closer to the Graphical Layout? 我的问题是,如何使EditText看起来更接近图形布局? Or is this a function of the emulation? 还是这是仿真的功能? On my device, which has a custom rom, the EditText is square but looks similar to the Graphical Layout, which is what I want. 在我的具有自定义rom的设备上, EditText是方形的,但看上去与我想要的“图形布局”相似。

I've tried setting the textAppearance to "@android:attr/textAppearanceSmall" . 我尝试将textAppearance设置为"@android:attr/textAppearanceSmall" This does help in that it changes the size of the text within the EditText to be viewable, but it does not affect the size of the EditText itself. 这确实有帮助,因为它可以将EditText中的文本大小更改为可见,但不会影响EditText本身的大小。

Here's the XML for my EditText: 这是我的EditText的XML:

<EditText
android:maxLines="1"
android:scrollHorizontally="true"
android:textAppearance="@android:attr/textAppearanceSmall"
android:layout_marginTop="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

I could post the full XML, but essentially this EditText is enclosed (along with the search icon ImageView) in a RelativeLayout that is within another RelativeLayout. 我可以发布完整的XML,但实际上,这个EditText包含在另一个RelativeLayout中的RelativeLayout中(连同搜索图标ImageView一起)。

Thanks for any help! 谢谢你的帮助!

EDIT By request, here is the full XML for the top search bar: 编辑根据要求,以下是顶部搜索栏的完整XML:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageButton
        android:id="@+id/IBSearchOverlayMic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@drawable/aslctr_search_overlay_blackbutton"
        android:src="@drawable/search_overlay_ic_microphone" />
    <ImageView
        android:id="@+id/IVSearchOverlayDivider1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/IBSearchOverlayMic"
        android:src="@drawable/search_overlay_division" />
    <ImageButton
        android:id="@+id/IBSearchOverlaySearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/IVSearchOverlayDivider1"
        android:background="@drawable/aslctr_search_overlay_blackbutton"
        android:src="@drawable/search_overlay_ic_searchwhite" />
    <RelativeLayout
        android:id="@+id/RLSearchOverlaySearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/IBSearchOverlaySearch"
        android:layout_alignBottom="@id/IBSearchOverlaySearch"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/IBSearchOverlaySearch"
        android:layout_centerVertical="true"
        android:background="@drawable/search_overlay_searchbg">
        <EditText
            android:id="@+id/ETSearchOverlaySearch"
            android:maxLines="1"
            android:scrollHorizontally="true"
            android:textAppearance="@android:attr/textAppearanceSmall"
            android:layout_marginTop="5dip"
            android:layout_marginLeft="5dip"
            android:layout_marginRight="5dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@id/ETSearchOverlaySearch"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dip"
            android:clickable="false"
            android:focusable="false"
            android:src="@drawable/search_actionbar_ic_searchcream" />
    </RelativeLayout>
</RelativeLayout>

I determined the problem. 我确定了问题。 The issue was that the EditText was inside the RelativeLayout...I think that messed with the padding, or perhaps the EditText's layout_height="wrap_content" meant that it extended vertically. 问题是EditText位于RelativeLayout内部...我认为这与填充物一团糟,或者EditText的layout_height =“ wrap_content”意味着它垂直延伸。 Here's the reworked XML: 这是重做的XML:

    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageButton
        android:id="@+id/IBSearchOverlayMic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@drawable/aslctr_search_overlay_blackbutton"
        android:src="@drawable/search_overlay_ic_microphone" />
    <ImageView
        android:id="@+id/IVSearchOverlayDivider1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/IBSearchOverlayMic"
        android:src="@drawable/search_overlay_division" />
    <ImageButton
        android:id="@+id/IBSearchOverlaySearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/IVSearchOverlayDivider1"
        android:background="@drawable/aslctr_search_overlay_blackbutton"
        android:src="@drawable/search_overlay_ic_searchwhite" />
    <ImageView
        android:id="@+id/IVSearchBackground"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/IBSearchOverlaySearch"
        android:layout_alignBottom="@id/IBSearchOverlaySearch"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/IBSearchOverlaySearch"
        android:layout_centerVertical="true"
        android:background="@drawable/search_overlay_searchbg" />
    <EditText
        android:id="@+id/ETSearchOverlaySearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/IBSearchOverlaySearch"
        android:layout_alignBottom="@id/IBSearchOverlaySearch"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/IBSearchOverlaySearch"
        android:layout_marginTop="5dip"
        android:layout_marginLeft="5dip"
        android:layout_marginRight="5dip"
        android:layout_marginBottom="0dip"
        android:paddingBottom="0dip"
        android:maxLines="1"
        android:scrollHorizontally="true" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/IBSearchOverlaySearch"
        android:layout_alignTop="@id/IBSearchOverlaySearch"
        android:layout_alignBottom="@id/IBSearchOverlaySearch"
        android:layout_centerVertical="true"
        android:layout_marginRight="15dip"
        android:clickable="false"
        android:focusable="false"
        android:src="@drawable/search_actionbar_ic_searchcream" />
</RelativeLayout>

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

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