我对在 Eclipse 中编写 Android 应用程序完全陌生。
话虽如此,我基于互联网上的代码并为我的布局提出了这个 xml 文件。 我无法让四个按钮具有相同的大小,当我玩其他部分时,进度条和它下面的文本会变得疯狂,显示在屏幕外。
有人可以查看代码并告诉我发生了什么吗?我简直不明白。 这是一张照片。
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp" >
<TextView
android:id="@+id/txt_currentDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="6"
android:gravity="center"
android:text="Current Date"
android:textSize="18dp"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/progressBarRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<ProgressBar
android:id="@+id/DailyCalorieProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="3"
android:progress="80" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textView1"
android:gravity="center"
android:text="Calorie Limit : "
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView2"
android:gravity="center"
android:text="2000 " >
</TextView>
<TextView
android:id="@+id/textView3"
android:gravity="center"
android:text="Calories Left : "
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView4"
android:gravity="center"
android:text="552" >
</TextView>
</TableRow>
<TextView
android:id="@+id/textView5"
android:gravity="center_horizontal"
android:text="____________________" >
</TextView>
<TableLayout
android:id="@+id/ButtonLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:stretchColumns="0,1" >
<TableRow
android:id="@+id/buttonRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingTop="10dp" >
<Button
android:id="@+id/btn_addFood"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:text="Add Food"/>
<Button
android:id="@+id/btn_addExercise"
android:layout_width="130dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:text="Add Exercise"/>
</TableRow>
<TableRow
android:id="@+id/buttonRow2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_recWeight"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:text="Record Weight" />
<Button
android:id="@+id/btn_sgstMeal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:text="Suggest Meal/Exercise" />
</TableRow>
</TableLayout>
</TableLayout>
编辑:
现在几乎可以正常工作了。
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp" >
<TextView
android:id="@+id/txt_currentDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="6"
android:gravity="center"
android:text="@string/CurrentDate"
android:textSize="18dp"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/progressBarRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<ProgressBar
android:id="@+id/DailyCalorieProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="3"
android:progress="80" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textView1"
android:gravity="center"
android:text="@string/CalorieLimit"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView2"
android:gravity="center"
android:text="@string/CalorieLimitData" >
</TextView>
<TextView
android:id="@+id/textView3"
android:gravity="center"
android:text="@string/CaloriesLeft"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView4"
android:gravity="center"
android:text="@string/CaloriesLeftData" >
</TextView>
</TableRow>
<TextView
android:id="@+id/textView5"
android:gravity="center_horizontal"
android:text="@string/Line" >
</TextView>
<TableRow
android:id="@+id/buttonRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingTop="10dp" >
<Button
android:id="@+id/btn_addFood"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="@string/AddFood"/>
<Button
android:id="@+id/btn_addExercise"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="@string/AddExercise"/>
</TableRow>
<TableRow
android:id="@+id/buttonRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingTop="10dp" >
<Button
android:id="@+id/btn_recWeight"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="@string/RecordWeight" />
<Button
android:id="@+id/btn_sgstMeal"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="@string/SuggestedMeal_Exercise" />
</TableRow>
</TableLayout>
最佳答案
您的布局并不是真正的“高效”。但是无论如何..要解决您的问题,您必须将 TableRow(包含按钮的那些)设置为
android:layout_width="fill_parent"
android:layout_height="wrap_content"
和你所有的按钮
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
0dip 不做任何事情。但是由于重量参数 android 无论如何都会测量实际尺寸,因此您不需要提供“相关”值
关于Android布局,设置按钮具有相同的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9960001/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat
我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain
是否可以为特定(或所有)项目使用多个布局?例如,我有几个项目,我想对其应用两种不同的布局。一个是绿色的,一个是蓝色的(但是)。我想将它们编译到我的输出目录中的两个不同文件夹中(例如v1和v2)。我一直在玩弄规则和编译block,但我不知道这是怎么回事。因为,每个项目在编译过程中只编译一次,我不能告诉nanoc第一次用layout1编译,第二次用layout2编译。我试过这样的东西,但它导致输出文件损坏。compile'*'doifitem.binary?#don’tfilterbinaryitemselsefilter:erblayout'layout1'layout'layout2'
我正在使用Rails3.1并在一个论坛上工作。我有一个名为Topic的模型,每个模型都有许多Post。当用户创建新主题时,他们也应该创建第一个Post。但是,我不确定如何以相同的形式执行此操作。这是我的代码:classTopic:destroyaccepts_nested_attributes_for:postsvalidates_presence_of:titleendclassPost...但这似乎不起作用。有什么想法吗?谢谢! 最佳答案 @Pablo的回答似乎有你需要的一切。但更具体地说...首先改变你View中的这一行对此#