2017-07-25 9 views
0

現在、アンドロイドアプリケーションを開発しようとしていますが、現在アクティビティのビューの縮尺を変えようとしています。アンドロイドのすべての画面サイズとデバイスをサポートするUIを構築する方法

画像では、解像度幅が10px(両方のデバイスでもっと分かりやすいように表示されていることがわかります)。画面のサイズは、5インチから10インチから区別されます。青色の長方形は、私が別のデバイスで拡大縮小したいものであるEditTextです。

ご覧のとおり、両方のデバイスのEditTextは同じサイズですが、ピクセル数が異なります。私は両方のデバイスが完全に同じに見えるようにしたいと私はこれを修正するためにすべてを試してみましたが、何も本当に私のためにうまくいくようです。

(これは私が問題を表示するために描くだけの例イメージですが、第二の画像は、私はそれが本当に間違ってどこに行くか作るとしようとするものである)

enter image description here

これは私が」とは何ですか固定取得しようとしてメートル:

enter image description here

+0

Iドンすなわちレイアウト幅と高さを設定するために使用されている方法に注目してください...使用あなたの質問をよく理解していない。あなたは正確に何を達成しようとしていますか?すべてのデバイスで編集テキストの幅がpxであるようにしますか?それともできるだけ幅を作っていますか? xmlレイアウトを投稿してください。 – allo86

+0

@Al Lelopath私はレイアウトがまったく同じであることを望んでいます。ご覧のように、editTextはお互いに大きなものですが、大きなデバイスのものはもっと大きくなるはずです。可能であれば、 'dp'の代わりに '%'を使って作業したいと思いますが、そうではありません。 – muyat

+0

ここでは、maxWidthが中心になるでしょう –

答えて

0

基本的にはこのような何か、あなたのための作業を行う必要があります。

<?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="wrap_content" 
    android:orientation="vertical" 
    android:weightSum="100"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="5" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="10" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="5" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="10" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="5" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="10" 
     android:orientation="horizontal" 
     android:weightSum="100"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="10" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="10" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="10" /> 

    </LinearLayout> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="5" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="10" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="5" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="10" /> 

</LinearLayout> 
+0

これを小さな画面用のmaxWidthとscrollViewと組み合わせると、これは良いことです。 –

+0

@ A.Steenbergenしかし、DPを使用して別のビューを分離するか、SPをtextsizeに使用する必要がある場合はどうすればよいですか? – muyat

+0

余白の場合はDPを使用する必要がありますが、線形レイアウトの場合はlayout_marginsの場合でも割り当て重量を占有します –

0

Android Studioを使用しているとします。このパーセントライブラリをインポートして、それぞれの幅と高さのパーセンテージを設定することができます。これにより、端末、つまり携帯電話、7インチタブレット、10インチタブレットに基づいて幅と高さのパーセンテージを変えることができ、同じルックアンドフィールを得ることができます。私は現在のプロジェクトでそれを使用し、それは完全に働いた。次のように

そして、あなたは、各デバイス、すなわちフォルダごとに異なるXMLファイルを持っていることを確認する必要があります:

layout (XML files for phone), 
layout-sw600dp (XML files for 7 inch Tablet), 
layout-sw720dp (XML files for 10 inch Tablet), 
layout-w600dp (XML files for 7 inch Tablet), 
layout-w720dp (XML files for 10 inch Tablet). 

は、その後、以下のようにAndroidManifest.xmlを上でサポート画面を追加します。

単にあなたのGradleすなわち

compile 'com.android.support:percent:25.3.0' 

に次の依存関係を追加し、以下のように続いてパーセンテージは

app:layout_widthPercent="100%" 
app:layout_heightPercent="35%" 

(Refer to code below) 

    ********************************************************************* 
    //** activity_main.xml 
    ********************************************************************* 

    <android.support.percent.PercentRelativeLayout 
     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" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:orientation="vertical" 
     tools:context=".MainActivity"> 

     <!-- Begin Header Section --> 
     <RelativeLayout 
      android:id="@+id/headerSection" 
      app:layout_widthPercent="100%" 
      app:layout_heightPercent="55%"> 

      <android.support.v4.view.ViewPager 
       android:id ="@+id/spotlightViewPager" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"> 
      </android.support.v4.view.ViewPager> 

      <RelativeLayout 
       android:id="@+id/headerRight" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" > 

       <Button 
        android:id="@+id/shareButton" 
        android:layout_width="wrap_content" 
        android:layout_height="30dp" 
        android:layout_marginRight="5dp" 
        android:layout_marginTop="5dp" 
        android:theme="@style/ShareButtonBackgroundTheme" 
        android:background="@drawable/shape" 
        android:text="@string/mainShare" /> 
      </RelativeLayout> 

     </RelativeLayout> 
     <!-- End Header Section --> 

     <!-- Begin Social & Weather Section --> 
     <RelativeLayout 
      android:id="@+id/socialWeatherSection" 
      android:layout_below="@id/headerSection" 
      app:layout_widthPercent="100%" 
      app:layout_heightPercent="10%"> 

      <RelativeLayout 
       android:id="@+id/socialWeatherLeft" 
       android:layout_width="140dip" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" > 

       <GridView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:id="@+id/socialmediaGridView" 
        android:horizontalSpacing="1dp" 
        android:stretchMode="columnWidth" 
        android:gravity="center" 
        android:background="#e5e5e5"> 
       </GridView> 
      </RelativeLayout> 

      <HorizontalScrollView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@+id/socialWeatherLeft" 
       android:scrollbars="none" 
       android:id="@+id/hsv" 
       android:layout_margin="1dp" 
       android:fillViewport="false"> 

       <LinearLayout 
        android:orientation="horizontal" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

        <GridView 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:id="@+id/weatherGridView" 
         android:horizontalSpacing="1dp" 
         android:stretchMode="columnWidth" 
         android:gravity="center" 
         android:background="#e5e5e5"> 
        </GridView> 

       </LinearLayout> 

      </HorizontalScrollView> 

     </RelativeLayout> 
     <!-- End Social & Weather Section --> 

     <!-- Begin Grid Navigation Section --> 
     <RelativeLayout 
      android:id="@+id/gridSection" 
      android:layout_below="@+id/socialWeatherSection" 
      app:layout_widthPercent="100%" 
      app:layout_heightPercent="35%"> 

      <GridView 
       android:id="@+id/gridView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:verticalSpacing="2dp" 
       android:horizontalSpacing="2dp" 
       android:layout_alignParentLeft="true" 
       android:numColumns="3" 
       android:stretchMode="columnWidth" 
       android:gravity="center" 
       android:background="#e5e5e5"> 
      </GridView> 

     </RelativeLayout> 
     <!-- End Grid Navigation Section --> 

    </android.support.percent.PercentRelativeLayout> 

************************************************************** 
//** AndroidManifest.xml 
************************************************************** 

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

    <!-- permission for GPS location --> 
    <!--<uses-permission android:name="android.permission.INTERNET" />--> 
    <!--<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />--> 
    <!--<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />--> 
    <!--<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />--> 
    <!--<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />--> 
    <!--<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />--> 
    <!--<uses-permission android:name="android.permission.CALL_PHONE" />--> 
    <!--<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>--> 
    <!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />--> 

    <!-- Tablet Fix --> 
    <uses-feature android:name="android.permission.INTERNET" android:required="false"/> 
    <uses-feature android:name="android.permission.ACCESS_FINE_LOCATION" android:required="false"/> 
    <uses-feature android:name="android.permission.ACCESS_NETWORK_STATE" android:required="false"/> 
    <uses-feature android:name="android.permission.ACCESS_WIFI_STATE" android:required="false"/> 
    <uses-feature android:name="android.permission.CHANGE_WIFI_STATE" android:required="false"/> 
    <uses-feature android:name="android.permission.CHANGE_NETWORK_STATE" android:required="false"/> 
    <uses-feature android:name="android.permission.CALL_PHONE" android:required="false"/> 
    <uses-feature android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="false"/> 
    <uses-feature android:name="android.permission.READ_EXTERNAL_STORAGE" android:required="false"/> 

    <application 
     android:name=".TestApplication" 
     android:allowBackup="true" 
     android:hardwareAccelerated="false" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:largeHeap="true" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 

     <activity android:name=".SplashScreen" android:theme="@android:style/Theme.NoTitleBar"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".MainActivity"> 
      <intent-filter> 
       <action android:name=".MAINACTIVITY" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
      <intent-filter> 
       <action android:name="android.intent.action.SEND" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
       <data android:mimeType="image/*" /> 
      </intent-filter> 
     </activity> 

     <activity android:name=".AgencyActivity"></activity> 

    </application> 

    <supports-screens 
     android:resizeable="false" 
     android:smallScreens="true" 
     android:normalScreens="true" 
     android:largeScreens="true" 
     android:xlargeScreens="true" 
     android:anyDensity="true" 
     android:requiresSmallestWidthDp="320" 
     android:compatibleWidthLimitDp="320" 
     android:largestWidthLimitDp="720"/> 

    <compatible-screens> 
     <!--no small size screens --> 

     <!--all normal size screens --> 
     <screen android:screenSize="normal" android:screenDensity="ldpi" /> 
     <screen android:screenSize="normal" android:screenDensity="mdpi" /> 
     <screen android:screenSize="normal" android:screenDensity="hdpi" /> 
     <screen android:screenSize="normal" android:screenDensity="xhdpi" /> 

     <!-- all large size screens --> 
     <screen android:screenSize="large" android:screenDensity="ldpi" /> 
     <screen android:screenSize="large" android:screenDensity="mdpi" /> 
     <screen android:screenSize="large" android:screenDensity="hdpi" /> 
     <screen android:screenSize="large" android:screenDensity="xhdpi" /> 

     <!-- all xlarge size screens --> 
     <screen android:screenSize="xlarge" android:screenDensity="ldpi" /> 
     <screen android:screenSize="xlarge" android:screenDensity="mdpi" /> 
     <screen android:screenSize="xlarge" android:screenDensity="hdpi" /> 
     <screen android:screenSize="xlarge" android:screenDensity="xhdpi" /> 

     <!-- Special case for Nexus 7 --> 
     <screen android:screenSize="large" android:screenDensity="213" /> 

     <screen android:screenSize="normal" android:screenDensity="480" /> 
     <screen android:screenSize="large" android:screenDensity="480" /> 
     <screen android:screenSize="xlarge" android:screenDensity="480" />` 

    </compatible-screens> 

</manifest> 
関連する問題