Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 尝试膨胀xml时ImageView和textView重叠_Android_Android Imageview_Textview_Android Inflate - Fatal编程技术网

Android 尝试膨胀xml时ImageView和textView重叠

Android 尝试膨胀xml时ImageView和textView重叠,android,android-imageview,textview,android-inflate,Android,Android Imageview,Textview,Android Inflate,我有一个包含imageview和textview的xml。textview放在imageview的右侧,但当我尝试膨胀xml时,imageview和textview重叠。任何帮助都将不胜感激 data.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout

我有一个包含imageview和textview的xml。textview放在imageview的右侧,但当我尝试膨胀xml时,imageview和textview重叠。任何帮助都将不胜感激

data.xml

    <?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="wrap_content" >

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:paddingBottom="5dp"
        android:src="@drawable/payback" />

    <TextView
        android:id="@+id/txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/img"
        android:paddingTop="5dp"
        android:text="33%" />

    <TextView
        android:id="@+id/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/img"
        android:paddingBottom="10dp"
        android:text="Important and Urgent" />

</RelativeLayout>

活动代码

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.check);

        content=(LinearLayout)findViewById(R.id.content);
        today=(TextView)findViewById(R.id.today);
        tomorrow=(TextView)findViewById(R.id.tomorrow);

        today.setOnClickListener(new TextView.OnClickListener() {                  

            @Override                 
            public void onClick(View v) {                     
                // TODO Auto-generated method stub  
                //Toast.makeText(ToDo.this, "Before"+content.getChildCount(), Toast.LENGTH_LONG).show();      
                content.removeAllViews();                      
                inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);     
                int id=0;                                              
                for (int idx = 0; idx < 4; idx++) {                             
                    id = idx + 1;                             
                    rel = (RelativeLayout) inflater.inflate(R.layout.data, null); 
                    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);                             
                    params.setMargins(0, 50, 0, 0);                             
                    txt = (TextView) rel.findViewById(R.id.txt);                             
                    txt.setText("AAA"+idx);                 

                    img = (ImageView) rel.findViewById(R.id.img);                             
                    img.setImageResource(R.drawable.payback);                             
                    img.setId(id);                              

                    content.addView(rel, params);                          
                    }                                           
                content.setVisibility(View.VISIBLE);                     
                }             
            });     
}
@覆盖
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.check);
content=(LinearLayout)findViewById(R.id.content);
今天=(TextView)findViewById(R.id.today);
明天=(TextView)findViewById(R.id.tomory);
today.setOnClickListener(新的TextView.OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
//Toast.makeText(ToDo.this,“在”+content.getChildCount(),Toast.LENGTH\u LONG.show()之前);
content.removeallview();
充气器=(LayoutInflater)getSystemService(Context.LAYOUT\u充气器\u SERVICE);
int id=0;
对于(intidx=0;idx<4;idx++){
id=idx+1;
rel=(RelativeLayout)充气器充气(R.layout.data,null);
RelativeLayout.LayoutParams params=新的RelativeLayout.LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
参数设置边距(0,50,0,0);
txt=(TextView)rel.findViewById(R.id.txt);
txt.setText(“AAA”+idx);
img=(ImageView)相对findViewById(R.id.img);
img.setImageResource(R.可提取的回报);
img.setId(id);
content.addView(rel,params);
}                                           
content.setVisibility(View.VISIBLE);
}             
});     
}
check.xml

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

    <RelativeLayout
        android:id="@+id/whiteboard"
        android:layout_width="250dp"
        android:layout_height="300dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="60dp"
        android:background="#FFFFFF" >

        <Button
            android:id="@+id/add"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="17dp"
            android:layout_marginLeft="20dp"
            android:text="Add" />

        <View
            android:id="@+id/bottomseperator"
            android:layout_width="200dp"
            android:layout_height="1dp"
            android:layout_above="@+id/add"
            android:layout_alignLeft="@+id/add"
            android:layout_marginBottom="10dp"
            android:background="#000000" />

        <View
            android:id="@+id/topseperator"
            android:layout_width="220dp"
            android:layout_height="1dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="35dp"
            android:background="#000000" />

        <TextView
            android:id="@+id/day"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="8dp"
            android:text="Day :"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/today"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/day"
            android:layout_alignBottom="@+id/day"
            android:layout_toRightOf="@+id/day"
            android:text="Today /"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/tomorrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/today"
            android:layout_alignBottom="@+id/today"
            android:layout_toRightOf="@+id/today"
            android:text="Tomorrow /"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/custom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/tomorrow"
            android:layout_alignBottom="@+id/tomorrow"
            android:layout_toRightOf="@+id/tomorrow"
            android:text="Custom"
            android:textSize="15sp" />

        <ScrollView
            android:id="@+id/contenntscroll"
            android:layout_width="200dip"
            android:layout_height="200dip"
            android:layout_alignBottom="@+id/whiteboard"
            android:layout_alignTop="@+id/whiteboard"
            android:layout_below="@+id/topseperator"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp"
            android:isScrollContainer="false"
            android:scrollbars="none" >

            <LinearLayout
                android:id="@+id/content"
                android:layout_width="200dp"
                android:layout_height="300dp"
                android:layout_marginTop="30dp"
                android:orientation="vertical" >

            </LinearLayout>
        </ScrollView>
    </RelativeLayout>

</RelativeLayout>

声明:

img.setId(id);

是导致问题的原因。删除此语句后,代码将正常工作。

删除img.setId(id)后,代码将正常工作。我能知道解释吗?这是因为相对人的内部问题。你是如何确定问题的?你以前曾面对过吗?假设我想在点击图片时做一些动作,我该怎么做呢?