草庐IT

android - ImageButtons 大小和位置在 Eclipse 中不起作用

coder 2023-12-24 原文

问题: 我似乎无法让我的 ImageButtons 出现在正确的位置或大小合适。

平台: 带有 Android API 16 的 Eclipse

问题: 我的 RelativeLayout 是 600x800,我的 ImageButtons 是 194x64,但是当我将它们放入编辑器时,它们是它们应该的两倍大。查看图片链接。

我的 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/main_portal_bg" >

    <RelativeLayout
        android1:layout_width="353dp"
        android1:layout_height="758dp"
        android1:layout_marginLeft="115dp"
        android1:layout_marginTop="29dp"
        android1:background="#000000" >
    </RelativeLayout>

    <ImageButton
        android1:id="@+id/new_customer_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_marginTop="89dp"
        android1:contentDescription="@string/back_button_desc"
        android1:background="@drawable/new_customer_button_selector" />

    <ImageButton
        android1:id="@+id/returning_customer_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_alignParentLeft="true"
        android1:layout_below="@+id/new_customer_button_selector"
        android1:contentDescription="@string/back_button_desc"
        android1:src="@drawable/returning_customer_button_selector" />

    <ImageButton
        android1:id="@+id/redeem_coupon_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_alignParentLeft="true"
        android1:layout_below="@+id/returning_customer_button_selector"
        android1:contentDescription="@string/back_button_desc"
        android1:src="@drawable/redeem_coupon_button_selector" />

    <ImageButton
        android1:id="@+id/info_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_alignParentLeft="true"
        android1:layout_below="@+id/redeem_coupon_button_selector"
        android1:contentDescription="@string/back_button_desc"
        android1:src="@drawable/info_button_selector" />

</RelativeLayout>

研究: 我尝试使用 FitXY 的 ScaleType,设置 MaxHeight 和 MinHeight,并使用 android:background 而不是 android:src。我能够使它们变小的唯一方法是使用图形编辑器通过按住 SHIFT 并拖动右下角来调整它们的大小。不幸的是,这也迫使它们自动对齐到布局的底部,当我尝试移动它们时,它们会弹回到原来的大小,所有其他按钮都会在布局周围移动。编辑 XML 只是完成了一部分。

问题: 每次我尝试在图形编辑器中移动一个按钮时,所有其他按钮都会在屏幕上以看似随机的模式移动。为什么会这样?

我设置的宽度为 194dp,高度为 64dp。更改这些值没有任何作用。为什么这不会影响我的 ImageButton 的实际宽度和高度?

当使用图形编辑器通过按住 SHIFT 键并拖动角来调整按钮大小时,这不会更改 XML 中的宽度和高度值,只会增加边距。请参阅下面生成的 XML:

   <ImageButton
        android1:id="@+id/new_customer_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_alignParentBottom="true"
        android1:layout_alignRight="@+id/returning_customer_button_selector"
        android1:layout_marginBottom="408dp"
        android1:layout_marginRight="86dp"
        android1:layout_marginTop="89dp"
        android1:background="@drawable/new_customer_button_selector"
        android1:contentDescription="@string/back_button_desc" />

这是我的最终目标:

请告诉我如何到达那里。这个简单的事情应该更容易。

最佳答案

阅读 developer.android.com/guide/practices/screens_support.html 上提供的信息后,我现在了解了 4 种不同类型的屏幕密度。感谢 CaseyB 提供的链接。

在使用我在 http://members.ping.de/~sven/dpi.html 找到的实用程序后,我计算出我的屏幕密度大约为 160 .

我的问题是 AVD 管理器创建的默认 AVD 将 LCD 密度设置为 240(高)。

将其设置为 160 后,我的项目使用正确大小的按钮呈现。

我将所有可绘制对象都放在可绘制对象文件夹中,因为我正在开发 1 屏幕分辨率和密度。如果我决定使用另一台平板电脑,那么我可能会使用其他文件夹。

提示:不要依赖 Eclipse 图形编辑器来调整 Assets 或调整大小。我不确定它是否完全准确。在尝试调整大小和间距时,我使用旧的编辑 XML 并运行项目的方法。

关于android - ImageButtons 大小和位置在 Eclipse 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12861968/

有关android - ImageButtons 大小和位置在 Eclipse 中不起作用的更多相关文章

  1. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  2. ruby-on-rails - s3_direct_upload 在生产服务器中不工作 - 2

    在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo

  3. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  4. ruby - 正则表达式在哪个位置失败? - 2

    我需要一个非常简单的字符串验证器来显示第一个符号与所需格式不对应的位置。我想使用正则表达式,但在这种情况下,我必须找到与表达式相对应的字符串停止的位置,但我找不到可以做到这一点的方法。(这一定是一种相当简单的方法……也许没有?)例如,如果我有正则表达式:/^Q+E+R+$/带字符串:"QQQQEEE2ER"期望的结果应该是7 最佳答案 一个想法:你可以做的是标记你的模式并用可选的嵌套捕获组编写它:^(Q+(E+(R+($)?)?)?)?然后你只需要计算你获得的捕获组的数量就可以知道正则表达式引擎在模式中停止的位置,你可以确定匹配结束

  5. ruby-on-rails - "assigns"在 Ruby on Rails 中有什么作用? - 2

    我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o

  6. ruby - 下载位置 Selenium-webdriver Cucumber Chrome - 2

    我将Cucumber与Ruby结合使用。通过Selenium-Webdriver在Chrome中运行测试时,我想将下载位置更改为测试文件夹而不是用户下载文件夹。我当前的chrome驱动程序是这样设置的:Capybara.default_driver=:seleniumCapybara.register_driver:seleniumdo|app|Capybara::Selenium::Driver.new(app,:browser=>:chrome,desired_capabilities:{'chromeOptions'=>{'args'=>%w{window-size=1920,1

  7. ruby - Heroku production.log 文件位置 - 2

    我想在heroku.com上查看我的应用程序日志的内容,所以我关注了thisexcellentadvice并拥有我所有的日志内容。但是我现在很想知道我的日志文件实际在哪里,因为“log/production.log”似乎是空的:C:\>herokuconsoleRubyconsoleforajpbrevx.heroku.com>>files=Dir.glob("*")=>["public","tmp","spec","Rakefile","doc","config.ru","app","config","lib","README","Gemfile.lock","vendor","sc

  8. ruby - 在 Ruby 中查找多个正则表达式匹配的模式和位置 - 2

    这应该是一个简单的问题,但我找不到任何相关信息。给定一个Ruby中的正则表达式,对于每个匹配项,我需要检索匹配的模式$1、$2,但我还需要匹配位置。我知道=~运算符为我提供了第一个匹配项的位置,而string.scan(/regex/)为我提供了所有匹配模式。如果可能,我需要在同一步骤中获得两个结果。 最佳答案 MatchDatastring.scan(regex)do$1#Patternatfirstposition$2#Patternatsecondposition$~.offset(1)#Startingandendingpo

  9. ruby - 字符串文字前面的 * 在 ruby​​ 中有什么作用? - 2

    这段代码似乎创建了一个范围从a到z的数组,但我不明白*的作用。有人可以解释一下吗?[*"a".."z"] 最佳答案 它叫做splatoperator.SplattinganLvalueAmaximumofonelvaluemaybesplattedinwhichcaseitisassignedanArrayconsistingoftheremainingrvaluesthatlackcorrespondinglvalues.Iftherightmostlvalueissplattedthenitconsumesallrvaluesw

  10. ruby - 为什么这个 eval 在 Ruby 中不起作用 - 2

    你能解释一下吗?我想评估来自两个不同来源的值和计算。一个消息来源为我提供了以下信息(以编程方式):'a=2'第二个来源给了我这个表达式来评估:'a+3'这个有效:a=2eval'a+3'这也有效:eval'a=2;a+3'但我真正需要的是这个,但它不起作用:eval'a=2'eval'a+3'我想了解其中的区别,以及如何使最后一个选项起作用。感谢您的帮助。 最佳答案 您可以创建一个Binding,并将相同的绑定(bind)与每个eval相关联调用:1.9.3p194:008>b=binding=>#1.9.3p194:009>eva

随机推荐