我有一个带有填充的RelativeLayout
和一个TextView
孩子。选择TextView
后,我希望突出显示的区域扩展到包含父级的填充,以便突出显示整个RelativeLayout
。
main.xml
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MyActivity"
android:textSize="30dp"
android:clickable="true"
android:background="@drawable/myback"
/>
myback.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@color/gray" />
<item android:state_focused="true" android:drawable="@color/gray" />
<item android:state_pressed="true" android:drawable="@color/gray" />
</selector>
MyActivity.java
package com.example.TextViewPadding;
import android.app.Activity;
import android.os.Bundle;
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
答案 0 :(得分:1)
如果您想要出现此行为,则需要将填充添加到TextView
而不是RelativeLayout
将父级的填充保持为0。