2013-04-23 59 views
0

我试图通过xml来实现这一点,而不是尝试失败。我已经尝试创建两个按钮,并通过ViewId调用它们,但随后它们不会显示在UI上,因为它们是自定义按钮。我怎么去解决它?什么是Android的以下java代码的xml等价物?

LinearLayout ll = new LinearLayout(this); 
      recButton = new CustomRecordButton(this); 
      ll.addView(recButton, 
       new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,0)); 
      playButton = new CustomPlayButton(this); 
      ll.addView(playButton, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,0)); 
      setContentView(ll); 

回答

1

这里是一个可能的方式

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto 
android:layout_width="fill_parent" 
android:layout_height="48dp" 
android:orientation="horizontal" > 

<package.to.my.CustomPlayButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 

<package.to.my.CustomPlayButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 

</LinearLayout> 
+0

所以,如果我的包被命名为包com.example.assignment22_audio_playback; 我会写 Ceelos 2013-04-23 20:39:21

+0

是的,当然CustomPlayButton扩展按钮 – Benoit 2013-04-23 20:43:40

+0

我试过了,但它不断给我类没有发现错误,当我通过图形查看它时,我也查找了类似的例子,但无法让它工作。无法找到以下类: - com.example.assignment22_audio_playback.CustomPlayButton(修复构建路径,编辑XML,创建类)。这是什么图形显示读取 – Ceelos 2013-04-23 20:46:30

相关问题