pinkred's mobile program

pinkred mobile programer

Archive for 7월 2015

[Android] G4 설정에서 앱 삭제시 아이콘이 크게 나오는 이슈

leave a comment »

LG-G4에서 설정에서 앱삭제시에 갑자기 아이콘이 크게 나오고 삭제가 불가한 적이 있었다.

알고 보니 res->xxxhdpi 폴더에 아주 큰 아이콘이 들어있었다. 유일하게 G4 설정에서 삭제시에 다른 단말과 다르게 아이콘이 나오는데 이 아이콘 때문에 발생하는 이슈였다. 해당 폴더에서 아이콘 삭제하여 이상없이 삭제되도록 수정하였다.

G4에서 삭제시에 아이콘의 영역을 fixed해야 하지 않을까 생각된다.

Written by pinkredmobile

2015/07/28 at 2:53 pm

프로그래밍(programming)에 게시됨

Tagged with , ,

[Android] App 고정 폰트로 구현하기

leave a comment »

앱을 제작하다보면 요구 사항으로 고정 폰트를 사용하는 경우가 있다.

앱내에 다양한 폰트가 적용되면 기존에 UI 디자인과 사뭇 달라 보이는 이슈로 인해서

앱이 이상하게 보이는 경우가 있어 폰트를 고정하여 앱이 디자인 철학과 맞도록 유지하도록 한다.

절차는 다음과 같다.

1. 외부 폰트를 구한다.

2. assest폴더에 외부 폰트를 넣는다.

3. 앱 시작시 외부 폰트를 읽는다.

4. 특정 컴포넌트에 폰트를 수정한다.

1번 사항은 넘어가고 2번 사항부터 시작하자면 앱의 assest폴더에 사용하려는 폰트를 복사해서 넣어주시면 됩니다.

확장자 명은 바꾸시지 않는 것이 좋습니다. 확장자가 폰트인 경우에는 압축율이 더 좋았습니다.

확장자에 따라서 똑같은 파일이라도 압축 방식을 다르게 합니다. 폰트파일이 압축율이 좋더군요.

3번 무료 폰트인 Naumbarungothic 폰트를 읽어 보았습니다. class로 만드셔도 되고 static 변수로 만드셔도 됩니다.

가끔씩 예외가 발생하는 경우가 있었습니다. 그런 경우에는 그냥 기본 폰트로 하도록 해주시면 됩니다.


try
{
	mTypeface = Typeface.createFromAsset(getAssets(), "NanumBarunGothic.ttf");
	mBoldTypeface = Typeface.createFromAsset(getAssets(), "NanumBarunGothicBold.ttf");
} catch (Exception e)
{
	mTypeface = Typeface.DEFAULT;
	mBoldTypeface = Typeface.DEFAULT_BOLD;
}


4번 폰트가 적용되는 컴포넌트에는 TextView, EditText, Button, RadioButton, CheckBox 가 있습니다.
해당 클래스를 상속받아서 폰트를 수정해 줍니다. flag에 Paint.SUBPIXEL_TEXT_FLAG를 넣으면 폰트가 더 부드러워 집니다.
그리고 ITALIC폰트는 없어서 그냥 넣었습니다.

public class CustomFontTextView extends TextView
{
        ...

        @Override
	public void setTypeface(Typeface tf, int style)
	{
		setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);

		switch (style)
		{
			case Typeface.NORMAL:
				setTypeface(mTypeface);
				break;

			case Typeface.BOLD:
				setTypeface(mBoldTypeface);
				break;
                
			case Typeface.ITALIC:
				setTypeface(mTypeface);
				break;
                
			case Typeface.BOLD_ITALIC:
				setTypeface(mBoldTypeface);
				break;
		}
	}
}

Written by pinkredmobile

2015/07/23 at 10:31 am

프로그래밍(programming)에 게시됨

Tagged with , ,

[Android] Issues : TextView 줄간격(lineSpacingExtra)

leave a comment »

안드로이드에서 TextView를 쓰는데 있어 줄간격이 문제가 있다.

android:lineSpacingExtra=“10dp”

위의 코드는 TextView에서 줄간격을 10dp로 하는 코드 인데 안드로이드 5.0미만 에서는

1줄인 경우에는 하단에 줄간격 여백이 나오고,

안드로이드 5.0이상에서는 1줄인 경우에는 하단에 줄간격 여백이 나오지 않는다.

위와 같은 이슈로 멀티라인 처리시에 문제가 발생한다.

또한 한줄이상이 될수 있는 UI에서 위아래로 10dp씩 여백을 주려고 할때 위만 10dp를 주고

아래는 줄간격으로 맞춘 후에 가운데 정렬을 할 경우 상하 가운데 정렬이 맞지가 않아 문제가 생기곤 했다.

그래서 줄간격 문제로 코드를 수정하기로 했다.

해결 방식은 TextView를 여러개를 만들어서 각각의 멀티 라인을 커버하는 것이다.

줄이 긴 경우에는 부적합하지만 2~3줄 정도는 충분히 커버 가능해서 UI 이슈를 해결해 줄 수 있다.


<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/line1TextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="1" />

        <TextView
            android:id="@+id/line2TextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:singleLine="true"
            android:maxLines="1" />
    </LinearLayout>

위와 같이 2줄 정도를 준비한다.

private void makeMultilineTextView(View view, final String text)
{
    if(view == null)
    {
        return;
    }

    final TextView line1TextView = (TextView) view.findViewById(R.id.line1TextView);
    final TextView line2TextView = (TextView) view.findViewById(R.id.line2TextView);

    line2TextView.setText(null);
    line2TextView.setVisibility(View.GONE);

    line1TextView.setText(text);
    line1TextView.post(new Runnable()
    {
        @Override
        public void run()
        {
            Layout layout = line1TextView.getLayout();

            if (layout == null || TextUtils.isEmpty(text) == true)
            {
                return;
            }

            int lineCount = layout.getLineCount();
            int length = text.length();

            // 2줄인 경우
            if (lineCount == 2)
            {
                int firstLineEnd = layout.getLineEnd(0);

                if (firstLineEnd < length)
                {
                    String line2Text = text.substring(firstLineEnd, length);

                    line2TextView.setVisibility(View.VISIBLE);
                    line2TextView.setText(line2Text);
                }
            } 
        }
    });
}

화면에 UI를 그리는 순간 텍스트 길이를 계산해서 라인별로 텍스트를 잘라서 넣어준다.

첫라인은 한줄로 하여 보여주면 되기 때문에 따로 넣어줄 필요는 없다.

Written by pinkredmobile

2015/07/22 at 2:27 pm