2015-01-08 6 views
7

मैं एक ऐप बनाने की कोशिश कर रहा हूं जिसमें टैबलेट और फोन के लिए दो अलग-अलग यूआई हैं, और मैं इसे लागू करने के लिए टुकड़ों का उपयोग कर रहा हूं। मैंने प्रत्येक टैबलेट और फोन लेआउट के लिए दो अलग-अलग एक्सएमएल फाइलें बनाई हैं और दोनों को गतिविधि_माइन.एक्सएमएल कहा जाता है, जिसमें फोन लेआउट को रेस/लेआउट फ़ोल्डर में रखा जा रहा है और टैबलेट लेआउट को res/layout-sw600dp फ़ोल्डर में रखा जा रहा है।टैबलेट यूआई मेरे ऐप पर काम नहीं करता

हालांकि जब मैं नेक्सस 10 एमुलेटर (एंड्रॉइड स्टूडियो) पर अपना ऐप चलाने की कोशिश करता हूं, तो यह स्वचालित रूप से डिफ़ॉल्ट फोन लेआउट पर जाता है। ऐप क्रैश या कुछ भी नहीं करता है लेकिन यह टैबलेट यूआई में चलाने के लिए फोन यूआई में चलाता है। मुझे नहीं पता कि इस त्रुटि का स्रोत क्या हो सकता है और इसलिए किसी भी मदद की सराहना की जाएगी।

यहां एक अपडेट है, मैंने फ़ोल्डर को res/layout-big-mdpi में नाम बदलने का प्रयास किया लेकिन अभी भी कोई बदलाव नहीं मिला। क्या यह संभव है कि यह एम्यूलेटर के साथ कुछ करने के लिए हो सकता है?

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.androidattack.www.sunshine" > 

    <uses-permission android:name="android.permission.INTERNET" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.androidattack.www.sunshine.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.androidattack.www.sunshine.DetailActivity" 
      android:label="@string/title_activity_detail" 
      android:parentActivityName="com.androidattack.www.sunshine.MainActivity" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.androidattack.www.sunshine.MainActivity" /> 
     </activity> 
     <activity 
      android:name="com.androidattack.www.sunshine.SettingsActivity" 
      android:label="@string/title_activity_settings" 
      android:parentActivityName="com.androidattack.www.sunshine.MainActivity" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.androidattack.www.sunshine.MainActivity" /> 
     </activity> 
     <provider 
      android:authorities="com.androidattack.www.sunshine" 
      android:name=".data.WeatherProvider" /> 
    </application> 

</manifest> 

sw600dp लेआउट:

यहाँ मेरी प्रकट है

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:divider="?android:attr/dividerHorizontal" 
    android:baselineAligned="false" 
    tools:context="com.androidattack.www.sunshine.MainActivity"> 

    <fragment 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:name="com.androidattack.www.sunshine.ForecastFragment" 
     android:id="@+id/fragment_forecast" 
     android:layout_gravity="center_vertical" 
     android:layout_weight="1" /> 

    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="2" 
     android:id="@+id/weather_detail_container"> 

    </FrameLayout> 


</LinearLayout> 

सामान्य लेआउट:

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/fragment_forecast" 
    android:name="com.androidattack.www.sunshine.ForecastFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="16dp" 
    android:layout_marginRight="16dp" 
    tools:context="com.androidattack.www.sunshine.ForecastFragment" 
    tools:ignore="MergeRootFrame" 
    tools:layout="@android:layout/list_content" /> 

और अंत में यह मेरा MainActivity.java वर्ग है:

/* 
* Copyright (C) 2014 The Android Open Source Project 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 
package com.androidattack.www.sunshine; 

import android.content.Intent; 
import android.content.SharedPreferences; 
import android.net.Uri; 
import android.os.Bundle; 
import android.preference.PreferenceManager; 
import android.support.v7.app.ActionBarActivity; 
import android.util.Log; 
import android.view.Menu; 
import android.view.MenuItem; 


public class MainActivity extends ActionBarActivity { 

    private final String LOG_TAG = MainActivity.class.getSimpleName(); 
    private boolean mTwoPane; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     if (findViewById(R.id.weather_detail_container) != null) { 
      // Tablet view 
      mTwoPane = true; 

      // In two-pane mode, show the detail view by adding 
      // or replacing the detail fragment using a 
      // fragment transaction. 

      if (savedInstanceState == null) { 
       getSupportFragmentManager().beginTransaction() 
         .replace(R.id.weather_detail_container, new DetailFragment()) 
         .commit(); 
      } 
     } else { 
      // Phone View 
      mTwoPane = false; 
     } 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      startActivity(new Intent(this, SettingsActivity.class)); 
      return true; 
     } 
     if (id == R.id.action_map) { 
      openPreferredLocationInMap(); 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 

    private void openPreferredLocationInMap() { 
     SharedPreferences sharedPrefs = 
       PreferenceManager.getDefaultSharedPreferences(this); 
     String location = sharedPrefs.getString(
       getString(R.string.pref_location_key), 
       getString(R.string.pref_location_default)); 

     // Using the URI scheme for showing a location found on a map. This super-handy 
     // intent can is detailed in the "Common Intents" page of Android's developer site: 
     // http://developer.android.com/guide/components/intents-common.html#Maps 
     Uri geoLocation = Uri.parse("geo:0,0?").buildUpon() 
       .appendQueryParameter("q", location) 
       .build(); 

     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setData(geoLocation); 

     if (intent.resolveActivity(getPackageManager()) != null) { 
      startActivity(intent); 
     } else { 
      Log.d(LOG_TAG, "Couldn't call " + location + ", no receiving apps installed!"); 
     } 
    } 
} 
+0

क्या आपके पास क्वालीफायर के साथ कोई अन्य संसाधन फ़ोल्डर्स है? हो सकता है कि उनमें से एक आपके sw600dp फ़ोल्डर पर प्राथमिकता ले रहा है? – stkent

+1

क्या आपने असली डिवाइस में कोशिश की? मेरे नेक्सस 7 में, मैं इसे मूल्य-sw6000dp के साथ संग्रहित कर सकता हूं। हो सकता है कि आप फ़ोल्डर मान-sw720dp (10 "टैबलेट) –

+1

बनाने का प्रयास कर सकते हैं क्या आपने लेआउट-बड़े की कोशिश की है? यही वह है जिसे हम अपने टैबलेट और फोन लेआउट को अलग करने के लिए उपयोग करते हैं। लेआउट-बड़े आपको 7" और 10 "टैबलेट दोनों प्राप्त करता है, और यदि आपको 10 के लिए कुछ अलग चाहिए "आप लेआउट-एक्सलार्ज का उपयोग कर सकते हैं। – Bruce

उत्तर

-2

लेआउट-एक्सएचडीपीआई का उपयोग इस विशिष्ट परिदृश्य और नैनोडग्री के लिए नेक्सस 7 या 10 टैबलेट एमुलेटर के लिए काम करेगा। मैं अपने एमुलेटर पर ठीक से लोड करने के लिए लेआउट-sw600dp कभी नहीं प्राप्त कर सकता था और इसके बजाय मैं वर्तमान में एक action_main.xml के साथ लेआउट-xhdpi और लेआउट-sw600dp दोनों के साथ सनशाइन बनाए रखता हूं।

+0

कुछ फोनों को लेआउट प्राप्त करने का दुर्भाग्यपूर्ण साइड इफेक्ट है। एक बेहतर समाधान होना चाहिए। शुरुआती लोगों के लिए –

0

क्या आपने डिवाइस को घुमाने पर लेआउट के साथ क्या होता है? (जैसे धूप परियोजना के अनुसार आप दोनों लेआउट-sw600dp बंदरगाह और लेआउट-sw600dp बनाने की जरूरत)/एमुलेटर

0

लेआउट-sw600dp 7 इंच टेबलेट के लिए है

लेआउट-sw720dp 10 इंच टेबलेट/एमुलेटर

के लिए है
9

मेरे लिए, कोड सही था, लेकिन मुद्दा एमुलेटर के साथ था। यदि आप अपने एमुलेटर को No skin के साथ सेट करते हैं, तो इसे काम करना चाहिए। उस त्वचा को हटाओ!

+0

वास्तव में एक गोचा – wakandan

संबंधित मुद्दे