2014-02-17 37 views
0

我有一個將文件上傳到我的應用程序的對話框活動。問題是,在10個英寸屏幕上的垂直作用,但如果我在一個7英寸的測試寬度只是變得更小(見圖片)寬度對話框活動7英寸

10 inch

7 inch

下面是我的代碼因爲我使用了7寸的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

<!-- Share document wrapper --> 
<LinearLayout 
    android:id="@+id/share_document_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:layout_marginBottom="20dp"> 

    <!-- Document views --> 
    <TextView 
     android:id="@+id/share_document_title" 
     android:text="@string/share_document_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 
    <EditText 
     android:id="@+id/share_document_single_selected_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:hint="@string/share_document_hint_edittext"/> 
    <TextView 
     android:id="@+id/share_document_selected_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:visibility="gone"/> 
</LinearLayout> 

<!-- Share account wrapper --> 
<LinearLayout 
    android:id="@+id/share_account_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="0dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp"> 

    <!-- Account views --> 
    <TextView 
     android:id="@+id/share_account_title" 
     android:text="@string/share_account_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 

    <LinearLayout 
     android:id="@+id/share_account_info_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="5dp" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:clickable="true" 
     android:background="@drawable/sliding_contact_menu_row_selector" > 
     <TextView 
      android:id="@+id/share_account_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
</LinearLayout> 

<!-- Share project wrapper --> 
<LinearLayout 
    android:id="@+id/share_project_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp"> 

    <!-- Project and folders views --> 
    <TextView 
     android:id="@+id/share_project_title" 
     android:text="@string/share_project_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginBottom="16dp"> 
     <Spinner 
      android:id="@+id/share_project_spinner" 
      android:layout_width="500dp" 
      android:layout_height="wrap_content" 
      android:spinnerMode="dialog"/> 

     <Button 
      android:id="@+id/share_project_create_new_project" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_marginLeft="16dp" 
      android:background="@drawable/green_button" 
      android:textColor="@color/MyWhite" 
      android:text="+" 
      android:textStyle="bold"/> 
    </LinearLayout> 


</LinearLayout> 

<!-- Share folder wrapper --> 
<LinearLayout 
    android:id="@+id/share_folder_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp"> 

    <!-- Project and folders views --> 
    <TextView 
     android:id="@+id/share_folder_title" 
     android:text="@string/share_folder_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 
    <LinearLayout 
     android:id="@+id/share_folder_info_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="16dp" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:clickable="true" 
     android:background="@drawable/sliding_contact_menu_row_selector" > 
     <ProgressBar 
      android:id="@+id/share_loader" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_marginRight="16dp" 
      android:layout_gravity="center_vertical" /> 
     <ImageView 
      android:id="@+id/share_folder_icon" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:src="@drawable/folder_icon" 
      android:layout_marginRight="16dp" 
      android:layout_gravity="center_vertical" /> 

     <TextView 
      android:id="@+id/share_folder_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="20sp"/> 
    </LinearLayout> 
</LinearLayout> 
    <LinearLayout 
     android:id="@+id/share_document_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_marginTop="20dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp"> 

    <!-- Documents views --> 
    <TextView 
     android:id="@+id/share_document_title" 
     android:text="@string/share_document_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 
    <RelativeLayout 
     android:id="@+id/share_document_info_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="16dp" 
     android:paddingTop="10dp" 
     android:paddingBottom="30dp" 
     android:clickable="false" 
     android:background="@drawable/sliding_contact_menu_row_selector" > 
     <ImageView 
      android:id="@+id/share_document_icon" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:src="@drawable/upload_document_purple" 
      android:layout_marginRight="16dp" 
      android:layout_alignParentLeft="true" /> 

     <TextView 
      android:id="@+id/share_document_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:layout_toRightOf="@id/share_document_icon"/> 

     <Switch 
      android:id="@+id/share_document_switch" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:switchPadding="200sp" 
      android:thumb="@drawable/switch_custom_share" 
      android:textOn="Als versie" 
      android:textOff="Nieuw" 
      android:textColor="@color/MyWhite" 
      android:layout_alignParentRight="true" 
      android:enabled="false"/> 
    </RelativeLayout> 
    <TextView 
     android:id="@+id/share_warning_message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/share_warning_message" 
     android:textColor="@color/MyRed" 
     android:textSize="14sp" 
     android:layout_marginBottom="16dp" 
     android:visibility="gone"/> 

</LinearLayout> 


<!-- Buttons bottom wrapper --> 
<View 
    android:layout_width="fill_parent" 
    android:layout_height="1dip" 
    android:background="?android:attr/dividerHorizontal" /> 
<LinearLayout 
    style="?android:attr/buttonBarStyle" 
    android:id="@+id/share_buttons_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <Button 
     style="?android:attr/buttonBarButtonStyle" 
     android:id="@+id/share_button_cancel" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/archive_cancel" 
     android:textSize="20sp"/> 
    <Button 
     style="?android:attr/buttonBarButtonStyle" 
     android:id="@+id/share_button_upload" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:textSize="20sp" 
     android:text="OK"/> 
</LinearLayout> 
</LinearLayout> 
</ScrollView> 

因爲我在這裏使用一個自定義的主題是我的自定義樣式:

<style name="MyShareTheme" parent="android:Theme.Holo.Light.Dialog"> 
    <item name="android:windowIsFloating">false</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowSoftInputMode">stateAlwaysHidden</item> 
    <item name="android:windowActionModeOverlay">true</item> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
</style> 

問:

我怎樣才能讓7寸屏幕上的對話框活動有大小在10英寸對話框一樣嗎?

編輯:

按照要求,我對我的佈局代碼爲10英寸的屏幕:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<!-- Share document wrapper --> 
<LinearLayout 
    android:id="@+id/share_document_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:layout_marginBottom="0dp"> 

    <!-- Document views --> 
    <TextView 
     android:id="@+id/share_document_title" 
     android:text="@string/share_document_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:layout_marginBottom="6dp" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 
    <EditText 
     android:id="@+id/share_document_single_selected_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/share_document_hint_edittext"/> 
    <TextView 
     android:id="@+id/share_document_selected_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:visibility="visible" 
     android:textSize="18sp"/> 
</LinearLayout> 

<!-- Share account wrapper --> 
<LinearLayout 
    android:id="@+id/share_account_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp"> 

    <!-- Account views --> 
    <TextView 
     android:id="@+id/share_account_title" 
     android:text="@string/share_account_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 

    <LinearLayout 
     android:id="@+id/share_account_info_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="5dp" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:clickable="true" 
     android:background="@drawable/sliding_contact_menu_row_selector" > 
     <ImageView 
      android:id="@+id/share_account_icon" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:src="@drawable/person_icon" 
      android:layout_marginRight="16dp" 
      android:layout_marginLeft="10dp" 
      android:layout_gravity="center_vertical" /> 
     <TextView 
      android:id="@+id/share_account_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="18sp"/> 
    </LinearLayout> 
</LinearLayout> 

<!-- Share project wrapper --> 
<LinearLayout 
    android:id="@+id/share_project_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp"> 

    <!-- Project and folders views --> 
    <TextView 
     android:id="@+id/share_project_title" 
     android:text="@string/share_project_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginBottom="16dp"> 
     <Spinner 
      android:id="@+id/share_project_spinner" 
      android:layout_width="500dp" 
      android:layout_height="wrap_content" 
      android:spinnerMode="dialog"/> 

     <Button 
      android:id="@+id/share_project_create_new_project" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_marginLeft="16dp" 
      android:background="@drawable/green_button" 
      android:textColor="@color/MyWhite" 
      android:text="+" 
      android:textStyle="bold"/> 
    </LinearLayout> 
</LinearLayout> 

<!-- Share folder wrapper --> 
<LinearLayout 
    android:id="@+id/share_folder_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp"> 

    <!-- Project and folders views --> 
    <TextView 
     android:id="@+id/share_folder_title" 
     android:text="@string/share_folder_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 
    <LinearLayout 
     android:id="@+id/share_folder_info_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="16dp" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:clickable="true" 
     android:background="@drawable/sliding_contact_menu_row_selector" > 
     <ProgressBar 
      android:id="@+id/share_loader" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_marginRight="16dp" 
      android:layout_gravity="center_vertical" /> 
     <ImageView 
      android:id="@+id/share_folder_icon" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:src="@drawable/folder_icon" 
      android:layout_marginRight="16dp" 
      android:layout_gravity="center_vertical" /> 

     <TextView 
      android:id="@+id/share_folder_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="18sp"/> 
    </LinearLayout> 
</LinearLayout> 
<LinearLayout 
    android:id="@+id/share_document_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp"> 

    <!-- Documents views --> 
    <TextView 
     android:id="@+id/share_document_title" 
     android:text="@string/share_document_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="6dp"/> 

    <!-- Divider --> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="?android:attr/dividerHorizontal" /> 
    <!-- /Divider --> 
    <RelativeLayout 
     android:id="@+id/share_document_info_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="16dp" 
     android:paddingTop="10dp" 
     android:paddingBottom="30dp" 
     android:clickable="false" 
     android:background="@drawable/sliding_contact_menu_row_selector" > 
     <ImageView 
      android:id="@+id/share_document_icon" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:src="@drawable/upload_document_purple" 
      android:layout_marginRight="16dp" 
      android:layout_alignParentLeft="true" /> 

     <TextView 
      android:id="@+id/share_document_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" 
      android:layout_toRightOf="@id/share_document_icon"/> 

     <Switch 
      android:id="@+id/share_document_switch" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:switchPadding="200sp" 
      android:thumb="@drawable/switch_custom_share" 
      android:textOn="Als versie" 
      android:textOff="Nieuw" 
      android:textColor="@color/MyWhite" 
      android:layout_alignParentRight="true" 
      android:enabled="false"/> 
    </RelativeLayout> 
    <TextView 
     android:id="@+id/share_warning_message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/share_warning_message" 
     android:textColor="@color/MyRed" 
     android:textSize="14sp" 
     android:layout_marginBottom="16dp" 
     android:visibility="gone"/> 

</LinearLayout> 


<!-- Buttons bottom wrapper --> 
<View 
    android:layout_width="fill_parent" 
    android:layout_height="1dip" 
    android:background="?android:attr/dividerHorizontal" /> 
<LinearLayout 
    style="?android:attr/buttonBarStyle" 
    android:id="@+id/share_buttons_wrapper" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <Button 
     style="?android:attr/buttonBarButtonStyle" 
     android:id="@+id/share_button_cancel" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/archive_cancel" 
     android:textSize="20sp"/> 
    <Button 
     style="?android:attr/buttonBarButtonStyle" 
     android:id="@+id/share_button_upload" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:textSize="20sp" 
     android:text="OK"/> 
</LinearLayout> 

</LinearLayout> 
+0

是否爲7英寸屏幕設計了單獨的佈局? – GrIsHu

+0

是的,我有一個單獨的7英寸屏幕布局 –

+0

什麼是您保存兩個不同的佈局xmls文件夾的名稱? –

回答

1

在10英寸屏幕上創建一個寬度值爲對話框的dimen.xml文件,並添加一個與7英寸屏幕相對應的值。這將處理對話框的寬度。

爲7英寸創建值-sw600dp文件夾,爲10英寸創建值-sw720dp。在這些文件夾中添加一個dimen.xml文件,其中包含您想要的寬度值。例如

爲sw600dp的dimen.xml文件

<resources> 

    <dimen name="popup_width">400dp</dimen> 

</resources> 

爲sw72dp的dimen.xml文件

<resources> 

    <dimen name="popup_width">500dp</dimen> 

</resources> 

和將其添加到以如下

layout_width="@dimen/popup_width" 
'layout_width'
0

試試這個..

ScrollView寬度match_parent

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

編輯:

可能,這將有助於

<LinearLayout 
    android:id="@+id/share_document_wrapper" 
    android:layout_width="0dp" 
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:layout_marginBottom="20dp"> 
+0

感謝您的回答,但它沒有工作,仍然保持相同的小尺寸。還有其他建議嗎? –

+0

@Stitchblade嘗試像我的編輯。 – Hariharan

+0

感謝您的回答,但如果我設置layout_width到0dp我得到以下警告/錯誤:Suspecious大小:這會讓視圖不可見,可能是用於layout_height –

0

設置你的滾動型的layout_width屬性match_parent

這會讓你的對話活動全屏。 和保證金屬性將使其平等。

+0

感謝您的回答,但哈里赫蘭Tamilan建議這不適合我,還有其他建議嗎? –

+0

檢查中,你把不同佈局的文件夾... –

+0

已經做了,但720dp文件夾佈局版本沒有滾動型的,所以問題不在於 –