【问题标题】:Android multi-fragment layout in landscape modeAndroid横向模式下的多片段布局
【发布时间】:2015-10-23 08:28:37
【问题描述】:

虽然我的代码可以工作,但我现在不知道它实际上在做什么。 我的应用程序是一个 RSS 阅读器,主要内容在 Fragment 中,其中包含 ListViewNewsStory 对象。单击列表项时,它会打开一个Intent,其中包含从 RSS 链接的网站。

现在的问题是,我不明白这里的Intent,这不是我以前使用过Intents 的方式。

另外,我必须使当我改变方向时,原始配置文件Fragment 占据屏幕的左半部分,链接的网页占据屏幕的右半部分。我折腾了一下,没用。我对方向变化做了一些研究,但我觉得用Fragments 做事总是会改变一切的运作方式。无论如何,这是Fragment 代码。任何想法将不胜感激。

public class HeadlineFragment extends Fragment {

    EditText input;
    Button search;
    ListView headlines;
    NewsDataSource ds;


    public HeadlineFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_headline,container,false);

        input = (EditText)v.findViewById(R.id.txtInput);
        search = (Button)v.findViewById(R.id.btnSearch);
        headlines = (ListView)v.findViewById(R.id.listView);

        try {
            ds = new NewsDataSource();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        headlines.setAdapter(new NewsDataSourceAdapter(this.getActivity(), ds));

        headlines.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView<?> parent,View view, int position, long id)
            {
                String url = NewsDataSource.stories[position].getLink();
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i);
            }
        });

        return v;
    }
    /*
    @Override
    public void onConfigurationChanged(Configuration newConfig){
        super.onConfigurationChanged(newConfig);


    }
    */
}

【问题讨论】:

    标签: java android android-fragments android-intent android-implicit-intent


    【解决方案1】:

    首先,关于Intent,它是一个隐含的Intent。当您将action 设置为ACTION_VIEW 并添加一个额外的URI / URL 时,操作系统会收到您想要打开一个可以导航到该URI / URL 的应用程序的消息。

    其次,要在横向模式下显示两窗格布局,您必须在 Fragment 中显示 RSS 内容,而不是像您当前所做的那样,在 Activity 中显示这些内容Fragments 在横向模式下并排在 Activity 中。请参阅 Retrieving a List of Contacts 示例,了解如何以纵向模式显示多窗格主详细信息布局。

    参考资料:

    1. Intents and Intent Filters.

    2. Planning for Multiple Touchscreen Sizes.

    【讨论】:

    • 这正是我一直在寻找的,但找不到。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多