popWindowdemo
1.main.xml
<?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:background="@android:color/white"
android:orientation="horizontal"
>
<LinearLayout
android:id="@+id/title_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="@drawable/bg"
android:gravity="center">
<TextView
android:id="@+id/title"
android:text="@string/str_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="@dimen/size_title"
android:textColor="@android:color/white"/>
<ImageView
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dip"
android:background="@drawable/icon_arrow_down"
/>
</LinearLayout>
</LinearLayout>
2.pop.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--
<ListView
android:id="@+id/pop_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="2dip"
android:cacheColorHint="#00000000"
></ListView>
-->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text=" :"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="1"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text=" :"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
/>
</LinearLayout>
3.(activity)PopwindowActivity.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class PopwindowActivity extends Activity
{
private ImageView arrow;
private boolean isOpenPop = false;
private PopupWindow window;
private ListView list;
private LinearLayout title_layout;
public static final String KEY = "key";
ArrayList<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContext = this;
arrow = (ImageView) findViewById(R.id.arrow);
title_layout = (LinearLayout) findViewById(R.id.title_layout);
title_layout.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
changPopState(v);
}
});
}
/**
* Pop
* */
public void changPopState(View v)
{
isOpenPop = !isOpenPop;
if (isOpenPop)
{
arrow.setBackgroundResource(R.drawable.icon_arrow_up);
popAwindow(v);
} else
{
arrow.setBackgroundResource(R.drawable.icon_arrow_down);
if (window != null)
{
window.dismiss();
}
}
}
private void popAwindow(View parent)
{
if (window == null)
{
LayoutInflater lay = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = lay.inflate(R.layout.pop, null);
window = new PopupWindow(v, 260, 300);
int x = (int) getResources().getDimension(R.dimen.pop_x);
int y = (int) getResources().getDimension(R.dimen.pop_y);
window = new PopupWindow(v, x, y);
}
window.setBackgroundDrawable(getResources().getDrawable(
R.drawable.pop_bg));
window.setFocusable(true);
window.setOutsideTouchable(false);
window.setOnDismissListener(new OnDismissListener()
{
@Override
public void onDismiss()
{
// TODO Auto-generated method stub
isOpenPop = false;
arrow.setBackgroundResource(R.drawable.icon_arrow_down);
}
});
window.update();
window.showAtLocation(parent, Gravity.CENTER_HORIZONTAL | Gravity.TOP,
0, (int) getResources().getDimension(R.dimen.pop_layout_y));
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.