无法在Android

时间:2016-05-14 14:14:04

标签: android android-layout android-tablet-layout

我正在尝试为我试图在模拟器上测试应用程序的Android平板电脑获得两个窗格显示( Nexus 10 )。我为此创建了activity_man.xml(在文件夹layout-sw600dp中)。它包含FrameLayout独有的android:id="@+id/movie_detail_container",如下所述。

  activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:divider="?android:attr/dividerHorizontal"
    android:orientation="horizontal"
    tools:context="akshit.android.com.popularmovies.MainActivity">

    <!--
    This layout is a two-pane layout for the Items master/detail flow.
    -->

    <fragment
        android:id="@+id/fragment_movie_main"
        android:name="akshit.android.com.popularmovies.MainActivityFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
        tools:layout="@android:layout/list_content" />

    <FrameLayout
        android:id="@+id/movie_detail_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="4" />

</LinearLayout>

基于此,我检查了如果视图包含ID,我应该mTwoPane = true以及启动DetailFragment(以支持movie_details_container)。但是mTwoPane仍然是假的。

public class MainActivity extends AppCompatActivity {
    private static final String DETAILFRAGMENT_TAG = "DFTAG";

    boolean mTwoPane = false;
    public static String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (findViewById(R.id.movie_detail_container) != null) {
            mTwoPane = true;
            Log.i(TAG, "mTwoPane value=" + mTwoPane);
            if (savedInstanceState == null) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.movie_detail_container, new DetailsActivityFragment(), DETAILFRAGMENT_TAG)
                        .commit();
            }
        } else {
            mTwoPane = false;
            Log.i(TAG, "mTwoPane value=" + mTwoPane);

        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
            startActivity(intent);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

请帮我弄清楚我哪里出错了。

2 个答案:

答案 0 :(得分:0)

创建没有框架的新虚拟设备。 AVD Manager-&gt;创建虚拟设备 - &gt; tablet-&gt; nexus 10 - &gt; next - &gt;选择sdk - &gt; next - &gt;取消选中&#34;启用设备框架&#34;

如果有帮助请标记为已回答。

答案 1 :(得分:0)

您是否检查过相关layout.xml文件中影片详图布局的ID是否也设为movie_detail_container?它应该与activity_main.xml文件的FrameLayout id。

中给出的id匹配