SLaks 2013-02-22 09:51 采纳率: 0%
浏览 3287
已采纳

android 中的动态相对布局

我想在布局顶端放置两个图像。用一个 xml 文件可以很好,但是我想动态的实现。ctdeasyone是一个透明的图像。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView 
        android:id="@+id/bck1" 
        android:src="@drawable/fish2"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"        
        android:scaleType="fitXY" 
        android:layout_gravity="center">
    </ImageView>

    <ImageView 
        android:id="@+id/bck2" 
        android:src="@drawable/ctdeasyone"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"        
        android:scaleType="fitXY" 
        android:layout_gravity="center">
    </ImageView>

</RelativeLayout>

但是只有第二个图像显示(透明的那个)。为什么呢?

public class TwoPicksOnEachOther extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Grabbing the Application context         
        final Context context = getApplication();                   

        RelativeLayout relativeLayout = new RelativeLayout(this);                   

        final ImageView iv = new ImageView(this);         
        iv.setImageResource(R.drawable.fish2);


        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(     
                RelativeLayout.LayoutParams.FILL_PARENT, 
                RelativeLayout.LayoutParams.FILL_PARENT);
        relativeLayout.addView(iv,lp);        

        // Creating transparent image
        final ImageView iv2 = new ImageView(this);
        iv.setImageResource(R.drawable.ctdeasytwo);
        RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(     
                RelativeLayout.LayoutParams.FILL_PARENT, 
                RelativeLayout.LayoutParams.FILL_PARENT);
        relativeLayout.addView(iv2,lp2);
        setContentView(relativeLayout);
    }        
}
  • 写回答

3条回答 默认 最新

  • zxd_72 2013-02-27 03:40
    关注

    在 abmenu.xml 项目中添加 showAsAction

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_save"
          android:icon="@drawable/ic_menu_save"
          android:title="@string/menu_save"
          // This line //
          android:showAsAction="ifRoom|withText" />
    </menu>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题