PostList

레이블이 Android인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Android인 게시물을 표시합니다. 모든 게시물 표시

2016년 8월 23일 화요일

LinearLayout 크기변경





LinearLayout
 메소드
 -getWidth(), getHeight() 가로길이나 세로길이 가져오기
 -setLayoutParams , getLayoutParams

LayoutParams(가로길이, 세로길이) 혹은 (가로길이,세로길이,비중) 으로 이루어짐

layout.post run안에서 getWidth()나 getHeight()해야 값을 받아온다.

layout.post(new Runnable() {
            @Override
            public void run() {

            }
        });



 LinearLayout의 세로크기를 가로크기와 같게 바꾸기


코드는 다음과 같다.

final LinearLayout layout = (LinearLayout)findViewById(R.id.linear);

layout.post(new Runnable() {
@Override
public void run() {
Log.e(" I ", "Width size= " + layout.getWidth());
Log.e(" I ", "Height size= " + layout .getHeight());

LinearLayout.LayoutParams position = new LinearLayout.LayoutParams(layout.getWidth(),layout.getWidth()); 
//LayoutParams(가로크기,세로크기) 설정, 
layout.setLayoutParams(position); 
}
});
Log.e(" E ", "Width size= " + layout.getWidth());
Log.e(" E ", "Height size= " + layout .getHeight());


layout.post run에서 레이아웃의 크기를 가져와야 정상적으로 가져온다.




LinearLayout의 setLayoutParams을 이용하여  position LayoutParams을 적용시켰다.



2016년 8월 21일 일요일

Intent 추가

Intent 안에는 Action 정보와 데이터 정보가 있음.

Intent는 시스템에 ~~를 해달라고 요청을 하는 용도로 쓰이는데, 그 요청 정보가 Action이다.

예를 들어 ACTION_DIAL tel:000-1111-1111 라고 하면 시스템에 해당 번호로 dial을 하라고 요청을 하는 것임.


명시적 인텐트(Explicit Intent)
- 인텐트에 클래스 객체나 컴포넌트 이름을 지정하여 호출할 대상을 확실히 알 수 있는 경우.
예)특정 Activity를 호출하는 경우(Main2Activity 등), 특정 액티비티를 지정해주고 있기 때문에 명시적 인텐트다.

암시적 인텐트(Implicit Intent)
- 액션과 데이터를 지정하긴 했지만 호출할 대상이 달라질 수 있는 경우
- 범주(category), 타입(Type), 컴포넌트(component), 부가 데이터(extras)
예) 위 ACTION_DIAL을 포함한 인텐트를 실행할 경우, 전화 어플이 여러 개 있으면 그 중 어떤 어플을 이용할지는 확실하게 정해주지 않기 때문에 암시적 인텐트이다.



Manifest: 어플이 시스템에 요청하는 권한들을 모두 포함하고 있음. 어플을 처음 다운받으면 ~~어플이 시스템 ~~(카메라, 사진첩 등)에 대한 권한을 요청하고 있습니다 라고 뜨는 것이 Manifest에 등록된 권한들 때문에 뜨는거임.
예) 어플에서 바로 전화를 이용할 수 있도록 만들기 위해서는 manifest에

<uses-permission android:name="android.permission.CALL_PHONE" />

을 추가해줘야 전화어플을 통하지 않고 바로 전화를 걸 수 있는 권한을 얻게 된다.


Intent를 이용해서 액티비티 간 데이터를 주고받는 법.

일단 액티비티1에
 public void onButton1Clicked(View V){

        Intent intent111 = new Intent(getApplicationContext(),Main2Activity.class);


//        Intent intent112 = new Intent();        intent111.putExtra("title","소녀시대");

        startActivity(intent111);

    }
라고 하고, 액티비티2의 onCreate() 안에
Intent intent113 = getIntent();

if (intent113 != null) {
    String title = intent113.getStringExtra("title");
    Toast.makeText(getApplicationContext(), "title : "+ title, Toast.LENGTH_LONG).show();
}
를 추가한다.


2016년 8월 15일 월요일

String buffer type

  • NORMAL : 디폴트 CharSequence 객체로 반환된다. XML 문서내 문자열은 입력시 소스 문자가 스타일 문자면 스타일 문자로 반환되고 아닌 경우는 일반 String 객체의 문자열로 반환된다.
  • SPANNABLE : 마크업문자를 넣을 수 있는 스타일 문자이다. 항상 스타일 문자로 반환된다.
  • EDITABLE : 편집가능한 스타일 문자이다. EditText는 EDITABLE 속성으로 반환된다.
출처 : http://wawoops67.blogspot.kr/2013/01/android-charsequence-string.html




stringbuffer 쓰는이유 - > 메모리가 유연해짐 , 추가 변경 제거 메소드있음
- 메모리 관련 http://blog.naver.com/nature128/220767646173
- 메소드설명  http://blog.naver.com/jjonghun1004/220787392582

안드로이드 키보드숨기기

1. 커서 o ,키보드 x

edittext = (EditText)findViewById(R.id.editText);
edittext.setTextIsSelectable(true);


2. 커서x 키보드x

edittext = (EditText)findViewById(R.id.editText);
edittext.setInputType(0);

3. edittext누를때 작동하게하면 강제로 내리는 효과

InputMethodManager imm=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(),0);

2016년 8월 11일 목요일

Intent 공부중


액티비티 , 서비스 ,

1.Explicit Intent 

-컴포넌트 이름이 명시된(Explicit) 인텐트

Intent intent = new Intent(Context,Main2Activity.class);

2.Implicit Intent

-컴포넌트 이름을 모를때 사용, 기능만 적용
-예) 카메라 실행할때 기본앱일지 새로설치한 앱일지 모름
-

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.naver.com"));

new Intent(Action);
new Intent(Action. Uri);

Intent intent = new Intent(Intent.ACTION_DIAL);//Intent.Action_DIAL = "android.intent.action.DIAL" , String 값

startActivity로 intent 를 실행하면 전화가 실행된다.

Intent intent = new Intent("action.kjhhjk1234");
//action.kjhhjk1234 이라는 Action을 실행한다.

Manifest

Manifest에서 intent-filter에 action,category를 주게 되면 intent를 실행시킬때 Action과 같을때 실행한다.

-> 예를 들어 Action을 android.intent.action.DIAL로 넣으면 intent-filter action에 android.intent.action.DIAL를 가진 어플이 실행된다. (여러어플이 가지고있을경우 선택하는창이 뜬다.)
->위에서 action.kjhhjk1234이라는 Action을 주고 manifest의 intent-filter에
<action android:name="action.kjhhjk1234" />를 주게되면 거기에 맞는 컨포넌트가 실행된다.

intent 만들때 카테고리를 입력하지않을경우  Default  카테고리로 자동 지정된다.
->인텐트 필터에서 Default 카테고리 추가해줘야된다.





        
            
                
                

            
        
        
            
                
                
            
        
    


데이터 주고받기

데이터 입력
putExtra(STRING,data)

intent.putExtra("name",editText.getText().toString());

데이터 받기

Intent intent = getIntent();
intent.getStringExtra("name")

int값일 경우

intent.getIntExtra("name",10)
10은 데이터가 없을때 기본값

2015년 8월 4일 화요일

xml Scroll

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button3"
android:layout_below="@+id/button"
android:id="@+id/ScrollView">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:background="#33ff0000"
android:text="Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello " />
</ScrollView>

버튼 클릭 연습

    Intent 변수1 = new Intent(Intent.ACTION_VIEW,Uri.parse("http://m.naver.com"));
    startActivity(변수1);
    인터넷
    Intent 변수2 = new Intent(Intent.ACTION_VIEW,Uri.parse("tel;/010-8033-6920"));
    startActivity(변수2);
    전화
    Intent 변수3= new Intent(Intent.ACTION_VIEW,Uri.parse("content://media/internal/images/media"));
    startActivity(변수3);
    갤러리
    finish();
    종료

버튼


  1. Button button3 = (Button) findViewById(R.id.button3);
  2.         button3.setOnClickListener(new View.OnClickListener() {
  3.             public void onClick(View v){
  4.                 Toast.makeText(getApplicationContext(),"중지",Toast.LENGTH_LONG).show();

                

testing

testing

java 시작