我正在尝试在Android中创建自定义对话框.但无论我试图做什么,我都无法改变对话框的宽度.它只是保持不变.以下是我将设置为对话框内容的视图.
<RelativeLayout
android:id="@+id/current_stats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible">
<ImageView android:id="@+id/player_image"
android:src="@drawable/person"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/player_name"
android:layout_below="@id/player_image"
android:layout_centerHorizontal="true"
android:text="Raja Ram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageButton android:id="@+id/dialog_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:background="#00000000"
android:src="@drawable/close_button_selector"/>
<ImageButton android:id="@+id/dialog_flip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:background="#00000000"
android:src="@drawable/rotate"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我在这个代码示例中使用wrap_content.我也尝试了以下选项
1)在创建对话框时设置自定义样式.
dialog = new Dialog(this,R.style.Theme_Dialog);
Run Code Online (Sandbox Code Playgroud)
风格如下
<resources>
<style name="Theme" parent="android:Theme">
</style>
<style name="Theme.Dialog">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
2)像这样在onCreateDialog()中设置视图的参数
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.player_info, null, false);
ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); …Run Code Online (Sandbox Code Playgroud) 除了使用之外,还有其他方法可以将字节数组转换为字符串吗 new String(bytearray)?确切的问题是我通过UDP连接在网络上传输json格式的字符串。在另一端,我在固定大小的字节数组中接收它(因为我不知道数组大小)并从字节数组中创建一个新字符串。如果我这样做,我分配的整个内存就变得不必要了。
为了避免这种情况,我将字节数组将其转换为字符串,截断字符串直到最后一个有效字符,然后将其转换为字节数组并从中创建一个新字符串。如果我这样做,它只会耗尽所需的内存,但垃圾收集频率会变得如此之高,因为它涉及更多数量的分配。做这个的最好方式是什么?
有人可以建议在Ruby on Rails中为文本字段设置提示文本(而不是默认文本)的最佳方法.目前我正在使用这个:
<%= text_field_with_auto_complete
"customer",
:contact_person, {
:value => 'last, first',
:style => 'color:#aaa;width:11em;',
:onfocus => "if(this.getValue()=='last, first'){this.clear();this.style.color = '#000';}",
:onblur => "if(this.getValue()==''){this.setValue('last, first');this.style.color = #aaa';}"
} %>
Run Code Online (Sandbox Code Playgroud)
文本字段附加到模型,然后附加到数据库中的值.此外,index.html中使用的相同html也在edit.html中使用,因此当我尝试编辑该字段时,默认值显示而不是数据库中的值.这样做的正确方法是什么?
注意:我不是要设置默认值,而只是提示需要在文本框中输入的内容.
谢谢,
拉贾拉姆
我是Android新手.我正在创建一个包含将动态填充的列表视图的应用程序.我的要求是当列表为空时,我想显示一条消息.我不想仅仅为了显示此消息而创建其他视图.有什么好办法吗?有什么建议?