Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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 ListView中的RelativeLayout页边距不显示_Android - Fatal编程技术网

Android ListView中的RelativeLayout页边距不显示

Android ListView中的RelativeLayout页边距不显示,android,Android,我当前使用的是一个列表视图,其中填充了一个带有RelativeLayout的自定义适配器。问题是相对长度的页边距不显示 以下是我的相对布局声明: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ArticleSnippet" android:layout_width="fill_parent" android:layout_h

我当前使用的是一个列表视图,其中填充了一个带有RelativeLayout的自定义适配器。问题是相对长度的页边距不显示

以下是我的相对布局声明:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ArticleSnippet" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="6dip" 
    android:layout_marginTop="10dip" 
    android:layout_marginLeft="10dip" 
    android:layout_marginRight="10dip" 
    android:background="@drawable/background_snippet" > 
    ... 
</RelativeLayout> 
<ListView 
    android:id="@+id/ArticleSnippets" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:divider="#fff" 
    android:dividerHeight="0sp"> 
</ListView> 

... 
ListView声明:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ArticleSnippet" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="6dip" 
    android:layout_marginTop="10dip" 
    android:layout_marginLeft="10dip" 
    android:layout_marginRight="10dip" 
    android:background="@drawable/background_snippet" > 
    ... 
</RelativeLayout> 
<ListView 
    android:id="@+id/ArticleSnippets" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:divider="#fff" 
    android:dividerHeight="0sp"> 
</ListView> 

在ListView中是否有什么特殊的操作来激活边距

提前感谢您的帮助


Lint(Dusariez JF)

以下是适配器的代码和主代码+主xml

ArticleSnippet代码:

package org.antihero.reader;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ArticleSnippetAdapter extends BaseAdapter {

    private List<RssMessage> elements;
    private Context mContext;

    public ArticleSnippetAdapter(Context mContext, List<RssMessage> elements) {
        this.mContext = mContext;
        this.elements = elements;
    }

    // TODO refactor this to limit number of views having an array ... 
    public View getView(int position, View convertView, ViewGroup parent) {

        RelativeLayout rowLayout;
        final RssMessage message = elements.get(position);

        if (convertView == null) {
            rowLayout = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.article_snippet, parent, false);
        } else {
            rowLayout = (RelativeLayout) convertView;
        }

        TextView title = (TextView) rowLayout.findViewById(R.id.ArticleTitle);
        title.setText(message.getTitle());

        TextView intro = (TextView) rowLayout.findViewById(R.id.ArticleIntro);
        intro.setText(message.getDescription());

        Log.i("antiheroReader", "ArticleSnippetAdapter::getView();");

        return rowLayout;
    }

    public int getCount() {
        Log.i("antiheroReader", "ArticleSnippetAdapter::getCount(); "+elements.size());
        return elements.size();
    }

    public Object getItem(int position) {
        Log.i("antiheroReader", "ArticleSnippetAdapter::getItem();");
        return elements.get(position);
    }

    public long getItemId(int position) {
        Log.i("antiheroReader", "ArticleSnippetAdapter::getItemId();");
        return position;
    }

    public void add(RssMessage element) {
        Log.i("antiheroReader", "ArticleSnippetAdapter::add();");
        elements.add(element);
    }

    public void empty() {
        Log.i("antiheroReader", "ArticleSnippetAdapter::empty();");
        elements.clear();
    }
}
package org.antihero.reader;
导入java.util.List;
导入android.content.Context;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.BaseAdapter;
导入android.widget.RelativeLayout;
导入android.widget.TextView;
公共类ArticleSnippetAdapter扩展了BaseAdapter{
私有列表元素;
私有上下文;
公共ArticleSnippetAdapter(上下文mContext、列表元素){
this.mContext=mContext;
这个元素=元素;
}
//TODO重构此文件以限制具有数组的视图数。。。
公共视图getView(int位置、视图转换视图、视图组父视图){
相对行布局;
最终RssMessage消息=elements.get(位置);
if(convertView==null){
rowLayout=(RelativeLayout)LayoutFlater.from(mContext).inflate(R.layout.article_片段,父项,false);
}否则{
rowLayout=(RelativeLayout)convertView;
}
TextView title=(TextView)rowLayout.findViewById(R.id.ArticleTitle);
title.setText(message.getTitle());
TextView intro=(TextView)rowLayout.findViewById(R.id.ArticleIntro);
intro.setText(message.getDescription());
i(“antiheroReader”,“ArticleSnippetAdapter::getView();”;
返回行布局;
}
public int getCount(){
Log.i(“antiheroReader”,“ArticleSnippetAdapter::getCount();”+elements.size());
返回元素。size();
}
公共对象getItem(int位置){
Log.i(“antiheroReader”、“ArticleSnippetAdapter::getItem();”;
返回元素。获取(位置);
}
公共长getItemId(int位置){
Log.i(“antiheroReader”,“ArticleSnippetAdapter::getItemId();”;
返回位置;
}
公共无效添加(RssMessage元素){
Log.i(“antiheroReader”、“ArticleSnippetAdapter::add();”;
元素。添加(元素);
}
public void empty(){
Log.i(“antiheroReader”,“ArticleSnippetAdapter::empty();”;
元素。清除();
}
}
主要代码:

package org.antihero.reader;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import org.antihero.reader.RssMessage;
import org.antihero.reader.AndroidSaxFeedParser;

public class AntiheroReader extends Activity {
    private ProgressDialog myProgressDialog = null; 
    private List<RssMessage> messages;
    private ArticleSnippetAdapter articleSnippetAdapter;
    private ListView articleSnippetView;

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            Log.i("antiheroReader", "handleMessage");
            articleSnippetAdapter.notifyDataSetChanged();
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        messages = new ArrayList<RssMessage>();
        articleSnippetAdapter = new ArticleSnippetAdapter(this, messages);
        articleSnippetView = (ListView) findViewById(R.id.ArticleSnippets);
        articleSnippetView.setAdapter(articleSnippetAdapter);

        OnClickListener myProgressBarShower = new View.OnClickListener() {          
            @Override
            public void onClick(View v) {
                // myProgressDialog is null.
                Log.i("antiheroReader", AntiheroReader.this.toString());
                myProgressDialog = ProgressDialog.show(AntiheroReader.this, "Please wait...", "Loading data ...", true, false);    
                Log.i("antiheroReader", myProgressDialog.toString());

                // Need to run stuff in the thread or the dialog isn't appearing
                new Thread() { 
                    public void run() {
                        URL feedUrl;
                        InputStream feedStream;
                         try{ 
                            if(myProgressDialog.isShowing()) {
                                Log.i("antiheroReader", "Dialog show");
                            } else {
                                Log.i("antiheroReader", "Dialog NOT show");
                            }

                            try {
                                feedUrl = new URL("http://192.168.56.1/index.xml");
                                //feedUrl = new URL("http://www.lalibre.be/rss/");
                            } catch (MalformedURLException e) {
                                throw new RuntimeException(e);
                            }
                            try {
                                feedStream = feedUrl.openConnection().getInputStream();
                                //Toast.makeText(AntiheroReader.this, feedStream.toString(), Toast.LENGTH_LONG).show();
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }

                            Log.i("antiheroReader", "ProgressDialog start parsing");

                            AndroidSaxFeedParser feed = new AndroidSaxFeedParser(feedStream);
                            List<RssMessage> messages = feed.parse();
                            articleSnippetAdapter.empty();

                            myProgressDialog.dismiss();
                            Log.i("antiheroReader", "ProgressDialog OFF");

                            int count = messages.size();
                            for(int i=0; i<count; i++) {
                                articleSnippetAdapter.add(messages.get(i));
                                Log.i("antiheroReader", messages.get(i).getTitle());
                                //Toast.makeText(AntiheroReader.this, messages.get(i).getTitle(), Toast.LENGTH_LONG).show();
                            }

                            handler.sendEmptyMessage(0);

                         } catch (Exception e) {  } 
                         // Dismiss the Dialog 
                         myProgressDialog.dismiss(); 
                    } 
                }.start(); 
            }
        };

        Button buttonHome = (Button) findViewById(R.id.ButtonHome);
        buttonHome.setOnClickListener(myProgressBarShower);

    }
}
package org.antihero.reader;
导入java.io.IOException;
导入java.io.InputStream;
导入java.net.MalformedURLException;
导入java.net.URL;
导入java.util.ArrayList;
导入java.util.List;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.os.Bundle;
导入android.os.Handler;
导入android.os.Message;
导入android.util.Log;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.ListView;
导入android.widget.Toast;
导入org.antihero.reader.RssMessage;
导入org.antihero.reader.AndroidSaxFeedParser;
公共类AntiheroReader扩展活动{
private ProgressDialog myProgressDialog=null;
私人列表消息;
私有ArticleSnippetAdapter ArticleSnippetAdapter;
私有列表视图;
私有处理程序=新处理程序(){
@凌驾
公共无效handleMessage(消息消息消息){
Log.i(“AntichoreReader”、“handleMessage”);
articleSnippetAdapter.notifyDataSetChanged();
}
};
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
messages=newarraylist();
articleSnippetAdapter=新的articleSnippetAdapter(此,消息);
articleSnippetView=(ListView)findViewById(R.id.ArticleSnippets);
articleSnippetView.setAdapter(articleSnippetAdapter);
OnClickListener myProgressBarShower=新视图。OnClickListener(){
@凌驾
公共void onClick(视图v){
//myProgressDialog为空。
Log.i(“antiheroReader”,antiheroReader.this.toString());
myProgressDialog=ProgressDialog.show(AntiheroReader.this,“请稍候…”,“正在加载数据…”,true,false);
Log.i(“antiheroReader”,myProgressDialog.toString());
//需要在线程中运行东西,否则对话框不会出现
新线程(){
公开募捐{
URL-feedUrl;
输入流-反馈流;
试试{
if(myProgressDialog.isShowing()){
Log.i(“反HeroReader”,“对话框显示”);
}否则{
Log.i(“antiheroReader”,“对话框不显示”);
}
试一试{
feedUrl=新URL(“http://192.168.56.1/index.xml");
//feedUrl=新URL(“http://www.lalibre.be/rss/");
}捕获(格式错误){
抛出新的运行时异常(e);
}
试一试{
feedStream=feedUrl.openConnection().getInputStream();
//Toast.makeText(antichorereader.this,feedStream.toString(),Toast.LENGTH_LONG.show();
}捕获(IOE异常){
抛出新的运行时异常(e);
 <View  
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:id="@+id/textview_listitem_spacer"
    android:layout_width="fill_parent"  
    android:layout_height="5dip"
    android:layout_below="@+id/textview_listitem_descr" 
    android:layout_toLeftOf="@+id/textview_listitem_cbox"
     />