2016-12-27 60 views
0

我在Android上處理多個Tablet和手機屏幕時嘗試了很多,但無法正確實現此目的。在某些情況下,我收到錯誤,有些不起作用。我也發佈了Stack Question,但沒有收到滿意的結果。 我想在平板電腦屏幕上並排顯示清單和說明,而僅在手機屏幕中列出清單。有沒有什麼好的和簡單的方法來做到這一點?我也嘗試this,但無法實現目標。需要在Android上處理大屏幕和小屏幕的工作示例

+0

你有沒有試着用multipane片段 –

+0

@poojarc是的,我試過。請參閱有問題的堆棧鏈接。 – user6750923

回答

0

是的,你可以做到這一點。有一種方法可以根據設備選擇佈局。

res/layout/my_layout.xml    // layout for normal screen size ("default") 
res/layout-large/my_layout.xml  // layout for large screen size 
res/layout-xlarge/my_layout.xml  // layout for extra-large screen size 
res/layout-xlarge-land/my_layout.xml // layout for extra-large in landscape orientation 

res/drawable-mdpi/graphic.png   // bitmap for medium-density 
res/drawable-hdpi/graphic.png   // bitmap for high-density 
res/drawable-xhdpi/graphic.png  // bitmap for extra-high-density 
res/drawable-xxhdpi/graphic.png  // bitmap for extra-extra-high-density 

res/mipmap-mdpi/my_icon.png   // launcher icon for medium-density 
res/mipmap-hdpi/my_icon.png   // launcher icon for high-density 
res/mipmap-xhdpi/my_icon.png  // launcher icon for extra-high-density 
res/mipmap-xxhdpi/my_icon.png  // launcher icon for extra-extra-high-density 
res/mipmap-xxxhdpi/my_icon.png  // launcher icon for extra-extra-extra-high-density 

在10' 的情況下,標籤創建中

res/layout-sw720dp/my_layout.xml 

在7' 的情況下的佈局標籤創建中

res/layout-sw600dp/my_layout.xml 


<?xml version="1.0" encoding="utf-8"?> 

<TextView 
    android:id="@+id/title_detailfragment" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/detail_fragment"/> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 
    <fragment 
     android:name="com.example.fyp_awais.tab.MainActivity$MyListFragment" 
     android:id="@+id/list_fragment" 
     android:layout_height="match_parent" 
     android:layout_width="0dp" 
     android:layout_weight="1" /> 
    <fragment 
     android:name="com.example.fyp_awais.tab.MainActivity$MyDetailFragment" 
     android:id="@+id/detail_fragment" 
     android:layout_height="match_parent" 
     android:layout_width="0dp" 
     android:layout_weight="1" /> 

</LinearLayout> 

的佈局
+0

是的,我知道這一點。但是如何在平板電腦佈局中同時顯示這兩個片段?我已經在問題中提到過了。你也可以看一下我的問題'http:// stackoverflow.com/questions/41330315/binary-xml-file-line-20-error-inflating-class-fragment-android' – user6750923

+0

取一個LinearLayout,然後取兩個RelativeLayouts併爲其分配權重。 –

+0

現在使用此RelativeLayouts來顯示您的片段 –

0

使用xhdpi資源並嘗試根據設備使用佈局參數設置運行時的所有佈局。

或讓機器人決定什麼是最好的設備創建以下文件夾

layout-large 
layout-small 
layout-sw600 
layout-sw720 

和類似的文件夾來組織你的佈局更好