2017-02-21 113 views
0

請幫助! 我很失落!花了數小時試圖解決這個問題! 在此先感謝!如何更改groupindicator箭頭xamarin andriod

問題:我已經改變了groupindicator,但圖像水平拉伸,我不能修復它

我曾嘗試: 所以我想轉換一個圖像到9修補圖像但是然後xamarin找不到它。 我試圖設置指標綁定(0,5),但箭頭,然後不出現, 我很迷茫,我如何可以用圖像替換可擴展列表視圖箭頭(groupindicator),然後該圖像不被拉伸,但固定大小我可以指定? 我也玩過設置選擇器xml,但似乎沒有任何工作!

在此先感謝!

settings_selector.xml

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

    <item 
     android:left="5dp" 
    android:right="5dp" 
    android:top="5dp" 
    android:bottom="5dp" 
     android:drawable="@drawable/uparrow" 
     android:state_expanded="true" /> 

    <item 
     android:left="11dp" 
    android:right="11dp" 
    android:top="12dp" 
    android:bottom="12dp" 
     android:drawable="@drawable/downarrow" /> 

</selector> 

Page.axml

`{<?xml version="1.0" encoding="utf-8"?> 
<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/myExpandableListview" 
    android:minWidth="25px" 
    android:minHeight="25px" 
    android:layout_width="match_parent" 
    android:groupIndicator="@drawable/settings_selector" 
    android:layout_height="match_parent" 

    />} 
+0

你檢查了我的答案嗎?任何問題? –

回答

0

我怎樣可以用圖像替換expanablelistview箭頭(groupindicator),然後該圖像不被拉伸,但固定的大小我可以指定?

組指示器的圖標圖像將始終伸展,通常是一個只包含頂部和底部可伸縮像素的9個補丁圖像可以解決問題。但是如果9補丁圖像不適合你,並且你堅持使用圖像資源,那麼解決圖像拉伸問題的一個簡單方法是爲你的ExpandableListView設置android:groupIndicator="@null"

然後在你的佈局列表組ExpandableListView(頭),手動添加ImageView例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/indicator" 
     android:src="@drawable/downicon" /> 
    <TextView 
     android:id="@+id/DataHeader" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="DataHeader" 
     android:layout_margin="2dp" 
     android:textStyle="bold" 
     android:paddingStart="50dp" 
     android:paddingLeft="50dp" /> 
</LinearLayout> 

最後在後面的代碼認購GroupClick事件的ExpandableListView的比如像這樣:

protected override void OnCreate(Bundle bundle) 
{ 
    base.OnCreate(bundle); 

    // Set our view from the "main" layout resource 
    SetContentView(Resource.Layout.Main); 

    var listView = FindViewById<ExpandableListView>(Resource.Id.myExpandableListview); 
    listView.SetAdapter(new ExpandableDataAdapter(this, Data.SampleData())); 
    listView.GroupClick += ListView_GroupClick; 
} 

private void ListView_GroupClick(object sender, ExpandableListView.GroupClickEventArgs e) 
{ 
    var view = e.ClickedView; 
    var indicator = view.FindViewById<ImageView>(Resource.Id.indicator); 
    if (e.Parent.IsGroupExpanded(e.GroupPosition)) 
    { 
     e.Parent.CollapseGroup(e.GroupPosition); 
     indicator.SetImageResource(Resource.Drawable.downicon); 
    } 
    else 
    { 
     e.Parent.ExpandGroup(e.GroupPosition); 
     indicator.SetImageResource(Resource.Drawable.upicon); 
    } 
} 

渲染這個演示的圖像:

enter image description here