336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

화면 가로/세로 고정하기

 

AndroidManifest.xml에서

<activity android:name=".challenge"
     
android:label="@string/app_name"
     
android:screenOrientation="portrait">
     <intent-filter>
         
 <action android:name="android.intent.action.MAIN" />
          
<category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
</activity>

 

<activity>안에서 android:screenOrientration 값을 넣어주시면 됩니다.

가로 = landscape

세로 = portrait

블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

[View Attribute]


XML에서 각각의 뷰가 가지는 속성을 Attribute로 지정해할 수 있습니다. 모든 View가 공통적으로 가지고 있는 Attribute에 대해서 먼저 설명하도록 하겠습니다.




layout_width, layout_height 


뷰의 넓이와 높이를 지정합니다. 


값으로 fill_parent, wrap_content 혹은 절대적인 수치를 가질 수 있습니다. 

fill_parent는 컨테이너 즉 부모가 가지는 길이를 모두 채울때 사용하고, 

wrap_content는 해당 뷰가 그려질 수 있게 필요한 길이만 차지한다는 것을 나타냅니다. 


절대적인 값도 넣을 수 있는데 픽셀의 경우 "100px", "100dp", "100sp" 처럼 수치와 단위를 써서 지정해줍니다. 

사용할 수 있는 단위는 px, in, mm, pt, dp, sp등이 있는데 주로 dp, sp, px이 주로 쓰입니다. 

px는 픽셀을 나타냅니다.

dp는 Density-independent Pixel이라고 화면의 밀도의 변화에 독립적으로 1dp는 160dpi의 화면에서의 1px에 대응됩니다. 

sp는 Scale-independent Pixel 이라고 하여 사용자의 폰트 선호도에 따라 크기가 달라지며 주로 폰트 사이즈 설정에 사용됩니다.



background


 배경색 혹은 그림을 지정해줍니다.

색은 #RGB, #ARGB, #RRGGBB, #AARRGGBB 의 포맷으로 지정해 줄 수 있습니다. 

통일성을 위해 보통 #AARRGGBB 포맷을 사용합니다. 

제일 앞에 AA는 투명도를 의미하고 나머지 부분은 RGB값을 의미합니다. 

투명도인 AA는 00이 완전 투명, FF가 불투명이 됩니다. 

예를 들어 android:background="#FFFF0000"로 지정해주면 빨간색으로 배경을 칠하게 됩니다. 

배경그림을 지정해줄 수도 있는데 android:background="@drawable/background_image" 와 같은 형태로 사용가능합니다. 

배경 그림은 리소스에 들어있는 jpg, png등의 그림을 배경으로 지정할 때 사용합니다.


visibility 


뷰가 화면에 보이게 할지 안보이게 할지를 설정합니다. 

visible, invisible, gone의 값을 가질 수 있습니다. 


visible 화면에 보임, 

invisible 화면에 보이지 않으나 공간은 차지함, 

gone 화면에 보이지도 않고 공간도 차지 하지 않음

블로그 이미지

By훈트

,
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
계속 속썩여온 비율 문제...
아이폰은 가로 세로 사이즈라도 고정되어 있지만..
안드롱은 지 맘대로니..어떻게 해서든 비율 문제를 풀어야 했다.
계속 끙끙거리다 드디어 정리됨 -_-;;

리스트의 한 로우는 2줄로 구성되어 있다.
첫번째 줄은 3칸, 두번째 줄은 1칸이고 첫번째 줄으니 비율은 1:1:2 이다.
이 에 대한 코드는 다음과 같다.

 
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        
        <TextView android:id="@+id/wordlist_row_level"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#66CCFF"
            android:textSize="20px"            
            android:gravity="center"/>
    
        <TextView android:id="@+id/wordlist_row_word"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#FF9900"
            android:textSize="20px"/>
            
        <TextView android:id="@+id/wordlist_row_date"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:background="#FFCCFF"
            android:textSize="20px"
            android:gravity="center"/>            
    </LinearLayout>
        
    <TextView android:id="@+id/wordlist_row_meaning"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:textSize="20px"
        android:gravity="center"/>        
</LinearLayout>

android:layout_width를 fill_parent나 wrap_content로 주면 안된다.
반드시 "0dp" 로 정해주자.
그리고 비율은 android:layout_weight 로 정해주면 된다.

[출처] [Android] layout 비율|작성자 로사


블로그 이미지

By훈트

,