-
setColorFilter:
The image filter effect can be realized through setColorFilter method
-
setTag(),getTag():
The setTag() method means to add an additional data to the View, and then use getTag() to get the data. The label can be set arbitrarily.
Let's take a look at the explanation of this in the SDK:
Tags :
Unlike IDs,Tags are not used to identify views,Tags are essentially an extra piece of iformation that can be assosciated with a view.They are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure.
Take a simple example:
Add a listener to multiple buttons, and each Button sets a different setTag. The listener uses getTag to distinguish which Button is pressed.
The code is as follows:
public class Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button1 = (Button) findViewById(R.id.Button01); Button button2 = (Button) findViewById(R.id.Button02); Button button3 = (Button) findViewById(R.id.Button03); Button button4 = (Button) findViewById(R.id.Button04); MyListener listener = new MyListener(); button1.setTag(1); button1.setOnClickListener(listener); button2.setTag(2); button2.setOnClickListener(listener); button3.setTag(3); button3.setOnClickListener(listener); button4.setTag(4); button4.setOnClickListener(listener); } public class MyListener implements View.OnClickListener { @Override public void onClick(View v) { int tag = (Integer) v.getTag(); switch (tag) { case 1: System.out.println("button1 click"); break; case 2: System.out.println("button2 click"); break; case 3: System.out.println("button3 click"); break; case 4: System.out.println("button4 click"); break; }}}}
The explanation of this example is still clear. Have a simple understanding of Tag.
3. This is a diagram of the relationship between view and its subclasses:
4. The addRule() method was mentioned yesterday, and a little content is added today:
Because there are many kinds of positioning methods in relative layout, API provides a unified method:
addRule(int verb, int anchor)
addRule(int verb)
Verb is a verb meaning, which is used to express above, below, to right of, to left of, align parent left wait.
The verb RelativeLayout has values under these constants. For example:
RelativeLayout.ABOVE
RelativeLayout.BELOW
RelativeLayout.ALIGN_LEFT
RelativeLayout.LEFT_OF
RelativeLayout.RIGHT_OF
The value of anchor can be relativelayout True, 0 means false, or the Id of other views. Fill in the corresponding value according to the specific verb:
Let me give you an example:
Let's take a look at the renderings first:
Next, let's look at the code implementation: (I hope to be a little patient. After careful reading, I will understand its usage)
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(this.addRelativeLayout()); } private RelativeLayout addRelativeLayout() { /*Here are five buttons defined: up, down, left, right, middle*/ RelativeLayout container = new RelativeLayout(this); Button btn1 = new Button(this); btn1.setId(11); btn1.setText("upper"); Button btn2 = new Button(this); btn2.setId(12); btn2.setText("lower"); Button btn3 = new Button(this); btn3.setId(13); btn3.setText("Left"); Button btn4 = new Button(this); btn4.setId(14); btn4.setText("right"); Button btn5 = new Button(this); btn5.setId(15); btn5.setText("in"); /*new 5 Layout parameters*/ RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(100, RelativeLayout.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(lp1); RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(lp1); RelativeLayout.LayoutParams lp4 = new RelativeLayout.LayoutParams(lp1); RelativeLayout.LayoutParams lp5 = new RelativeLayout.LayoutParams(lp1); /*Add rules to each parameter and dynamically set its relevant position*/ lp5.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); lp1.addRule(RelativeLayout.ABOVE, btn5.getId()); lp1.addRule(RelativeLayout.ALIGN_LEFT, btn5.getId()); lp2.addRule(RelativeLayout.BELOW, btn5.getId()); lp2.addRule(RelativeLayout.ALIGN_LEFT, btn5.getId()); lp3.addRule(RelativeLayout.LEFT_OF, btn5.getId()); lp3.addRule(RelativeLayout.ALIGN_BASELINE, btn5.getId()); lp4.addRule(RelativeLayout.RIGHT_OF, btn5.getId()); lp4.addRule(RelativeLayout.ALIGN_TOP, btn5.getId()); /*Add 5 view s to the container*/ container.addView(btn5, lp5); container.addView(btn1, lp1); container.addView(btn2, lp2); container.addView(btn3, lp3); container.addView(btn4, lp4); return container; }
5. The above code involves another problem:
lp1.addRule(RelativeLayout.ALIGN_LEFT, btn5.getId());
lp3.addRule(RelativeLayout.ALIGN_BASELINE, btn5.getId());
What is this?
We only mentioned five kinds of verb above, and the above two can be understood as baselines.
Align_ Take baseline as an example to explain through examples: add two adjacent textviews and give the second TextView a larger padding (such as 20dp). If align is added in the second TextView_ Baseline, see what the difference is.
(without reference line)
(add baseline)
As can be seen from the above, the second TextView moves upward to ensure that hello and world are on the same level.
END