2011-07-04 19 views
3

ボタンをクリックすると、マップビューの周囲に余白を描こうとしています。マップビューの周りに境界線を描画する方法

これは私が試したことであり、動作しません。マップビューは相対レイアウト内にあります。

LayoutInflater inflater = getLayoutInflater(); 

LinearLayout mView = (LinearLayout) inflater.inflate(
         R.layout.map_view_create_ps, mapView, false); 

GeoPoint viewLoc = mapView.getMapCenter(); 
MapView.LayoutParams params = new MapView.LayoutParams(
         LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 
         viewLoc, 

MapView.LayoutParams.BOTTOM_CENTER); 
       mView.setLayoutParams(params); 
       mapView.addView(mView); 
       mView.setVisibility(View.VISIBLE); 

上記のボタンがクリックされたときに

私create_ps_layoutは、このような

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:background="@android:color/transparent"> 
<LinearLayout android:layout_width="fill_parent" 
    android:id="@+id/linearLayout1" android:orientation="vertical" 
    android:layout_height="fill_parent" 
    android:background="@drawable/rounded_boarder"></LinearLayout> 

</LinearLayout> 

ようで、描画可能な背景これは動作しません。この

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" android:padding="10dp"> 
<solid android:color="@color/translucent_black" /> 
<corners android:bottomRightRadius="30dp" 
    android:bottomLeftRadius="30dp" android:topLeftRadius="30dp" 
    android:topRightRadius="30dp" /> 
    <stroke android:width="2dip" android:color="#FFB600"/> 
</shape> 

のようなものであると呼ばれていますしかし、皆さんはmapview whの周りに境界線を描く方法について正しい方向に私を指摘できましたか?ボタンが選択されていますか?

答えて

10

を使用すると、1つのRelativeLayoutでのMapViewと、次のようにRelativeLayoutのパディングプロパティを設定入れる:

 <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" android:layout_weight="1" 
      android:background="#444" android:padding="2dp"> 

      <com.google.android.maps.MapView 
       android:id="@+id/mapView" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:apiKey="YOUR-MAP-KEY" 
       android:clickable="true"/> 
     </RelativeLayout> 
1

は、次の手順に従います。

1-以下のコードで描画可能にimage_border.xmlを作成します。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item> 
    <shape android:shape="rectangle" > 
     <gradient 
      android:angle="90" 
      android:centerColor="#30ffffff" 
      android:endColor="#30ffffff" 
      android:startColor="#30ffffff" /> 
    </shape> 
</item> 
<item 
    > 
    <shape android:shape="rectangle" > 
     <solid android:color="#30ffffff" /> 
    </shape> 
</item> 

2-別のXML image_bordを作成以下のコードで描画可能でerless.xml:あなたのonClick実装で

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item> 
    <shape android:shape="rectangle" > 
     <gradient 
      android:angle="90" 
    ></gradient> 
    </shape> 
</item> 
<item 
    > 
<shape android:shape="rectangle" > 
    </shape> 
</item> 

3-このコードを追加:として追加follows.andとして

 wp1.setOnClickListener(new OnClickListener() { 
    @Override 
    public void onClick(View v) { 


     //wp1 to add a boarder if selected 
     wp1.setBackgroundDrawable(getResources().getDrawable(
        R.drawable.image_border)); 
      wp1.setPadding(8, 8, 8, 8); 
     //wp3 to hide the boarder if not selected 
     wp3.setBackgroundDrawable(getResources().getDrawable(
        R.drawable.image_borderless)); 

     } 
    }); 
1

は、レイヤーリストを作成しますあなたの相対的なレイアウトの背景。これは、ドロップシャドウとの境界を与える

ここに、これ以上の詳細のリンクhttp://www.uifuel.com/android-creating-a-drop-shadow-in-xml-layout/

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

    <!-- Drop Shadow Stack --> 
    <item> 
     <shape> 
      <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" /> 
      <solid android:color="#00CCCCCC" /> 
     </shape> 
    </item> 
    <item> 
     <shape> 
      <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" /> 
      <solid android:color="#10CCCCCC" /> 
     </shape> 
    </item> 
    <item> 
     <shape> 
      <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" /> 
      <solid android:color="#20CCCCCC" /> 
     </shape> 
    </item> 
    <item> 
     <shape> 
      <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" /> 
      <solid android:color="#30CCCCCC" /> 
     </shape> 
    </item> 
    <item> 
     <shape> 
      <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" /> 
      <solid android:color="#50CCCCCC" /> 
     </shape> 
    </item> 

    <!-- Background --> 
    <item> 
    <shape> 
      <solid android:color="@color/white" /> 
     <corners android:radius="3dp" /> 
    </shape> 
    </item> 
</layer-list> 
1

単純なストローク矩形のドロアブル(xmlシェイプ)を作成し、マップビューで切り替えます。 ここにサンプルがあります。わかりやすくMapViewの代わりにSurfaceViewを使用していますが、かなり同じように動作するはずです。

のres /描画可能/ red_frame.xml:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <stroke android:color="#ff0000" android:width="3dp"/> 
    <padding android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="3dp" /> 
</shape> 

のres /レイアウト/ activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <CheckBox 
      android:id="@+id/frame_switch" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:text="Show frame" /> 

    <SurfaceView 
      style="@android:style/TextAppearance.Large" 
      android:id="@+id/target" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@id/frame_switch"/> 

</RelativeLayout> 

そして最後のJavaのり - MainActivity.java:

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     final View target = findViewById(R.id.target); 
     final CheckBox checkbox = (CheckBox) findViewById(R.id.frame_switch); 

     checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { 
       target.setBackgroundResource(isChecked ? R.drawable.red_frame : 0); 
      } 
     }); 
    } 
} 
関連する問題